Add support for linking with Mold
yorickpeterse opened this issue · comments
Description
Mold is a linker that can be quite a bit faster compared to lld, and even more so compared to the system linker (depending on what the system linker is of course).
Similar to how we detect and use LLD, we should detect and use Mold. If both are available, we should favour Mold over LLD. Mold doesn't support Windows, and for macOS sold is required instead. As such, we should only perform the Mold check on Linux and BSD.
As we'll now have two X_is_availalbe
functions, the logic they use for checking if the command is available should be extracted into a separate function such that we can reuse it.
In addition, we should add a flag to force the use of the default/system linker. This is useful for comparing performance, but also in case a platform does have LLD/mold installed, but for some reason can't use it (#654 for example).
Related issues
Related work
No response
To illustrate the difference, this is with LLD:
$ for i in (seq 0 5)
../target/release/inko build -i test ./build/inko-tests.inko -o ./build/inko-tests --timings | rg Link
end
Link 95 msec (8%)
Link 86 msec (7%)
Link 113 msec (10%)
Link 88 msec (8%)
Link 90 msec (8%)
Link 87 msec (8%)
And this is with Mold:
$ for i in (seq 0 5)
../target/release/inko build -i test ./build/inko-tests.inko -o ./build/inko-tests --timings | rg Link
end
Link 57 msec (5%)
Link 58 msec (5%)
Link 63 msec (6%)
Link 59 msec (5%)
Link 56 msec (5%)
Link 55 msec (5%)
Testing this with some other projects as well, it seems using Mold can easily cut link times in half, resulting in a total reduction of compile times of 3-5%.