-
-
Notifications
You must be signed in to change notification settings - Fork 326
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
Conversation
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. 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. |
There was a problem hiding this 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.
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. |
Installing with that action is in the 1sec range. |
On this run, pytest got lucky, with 40 sec shaved on the build times. |
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. |
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.