Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Use faster mold linker to reduce build time by ≈>30 sec #3681

Merged
merged 3 commits into from
May 2, 2024

Conversation

echoix
Copy link
Member

@echoix echoix commented May 2, 2024

I’ve known about the mold linker for years now. It is a drop in replacement for Unix linkers, but several times faster. The design goal was to be able to link chromium in the one second range, with speeds approaching cp.

https://github.com/rui314/mold has a graph and table of the performance. Phoronix has multiple articles on the subject, that’s where I first learned about it.

The author is the same that created LLVM’s lld linker at the time, and that is still several times faster than what existed before.

I’ve initially wanted to speed up the
CodeQL c-cpp build, as since this build is profiled, it is already slower than normal builds. It still saves about 30 seconds.

I have chosen to not use the mold linker everywhere, to keep the usual linker in the Ubuntu build where most tests are done. For other workflows where a build is needed, but only for using the compiled binaries, like the Pylint workflow.

I’ve made at least 3 reruns of the same commits before and after to get an estimate of the build times (across different hardware allocated by GitHub Actions).

I don’t know why I didn’t think about this, as I already knew that build times were still too long when using ccache (I have been exploring using it on a couple of occasions), and one of the factors in play is that ccache can accelerate compilation, not linking. So the remaining time attributed to the linker could be reduced, and it represents 30 secs. That also means that the remaining time would be attributed to the various Python scripts used during the build, that could be further optimized.

@github-actions github-actions bot added the CI Continuous integration label May 2, 2024
@echoix echoix added this to the 8.4.0 milestone May 2, 2024
@echoix
Copy link
Member Author

echoix commented May 2, 2024

I'm using the GitHub action setup-mold, even if it doesn't have the usual version tags, just because it updates the version downloaded on every release, and we don't have to manually keep the URLs up to date. The content is really simple, it downloads and sets up a symlink.
https://github.com/rui314/setup-mold/blob/6bebc01caac32fb5251ee64f60cea0322d0e6574/action.yml

name: 'Setup mold'
description: 'Install mold as the default linker'
inputs:
  mold-version:
    description: 'The mold version to download'
    default: '2.30.0'
  make-default:
    description: 'Make mold the default linker'
    default: true
runs:
  using: composite
  steps:
    - run: |
        set -x
        echo "mold ${{ inputs.mold-version }}"
        if [ "$(whoami)" = root ]; then SUDO=; else SUDO=sudo; fi
        wget -O- --timeout=10 --waitretry=3 --retry-connrefused --progress=dot:mega https://github.com/rui314/mold/releases/download/v${{ inputs.mold-version }}/mold-${{ inputs.mold-version }}-$(uname -m)-linux.tar.gz | $SUDO tar -C /usr/local --strip-components=1 --no-overwrite-dir -xzf -
        test ${{ inputs.make-default }} = true -a "$(realpath /usr/bin/ld)" != /usr/local/bin/mold && $SUDO ln -sf /usr/local/bin/mold "$(realpath /usr/bin/ld)"; true
      shell: bash
      if: runner.os == 'linux'

I don't think I would've written something really better, so I'm keeping it as is, but pinned with the full commit hash.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the download and setup of the tool, using the action makes sense (although it looks strange I must say). The speedup is worth the try for the shorter workflows. I agree with not including to the more standardized ones like Ubuntu and GCC.

@echoix
Copy link
Member Author

echoix commented May 2, 2024

The version available on Ubuntu 22.04 is way too old, so I would've needed to download a binary from a release somehow anyways.

@echoix
Copy link
Member Author

echoix commented May 2, 2024

Installing with that action is in the 1sec range.

@echoix
Copy link
Member Author

echoix commented May 2, 2024

On this run, pytest got lucky, with 40 sec shaved on the build times.

@echoix
Copy link
Member Author

echoix commented May 2, 2024

I'm curious on how it will look like with cmake and ninja based builds. Probably that our non essential builds (like enough to run Pylint in Python code quality), could use the already faster cmake+ninja build including mold as a linker.

@echoix echoix merged commit 9dc6fc6 into OSGeo:main May 2, 2024
27 checks passed
@echoix echoix deleted the mold branch May 3, 2024 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants