Link 3x faster with gold
Since GHC 7.8, you can tell GHC and cabal (at run time without having to recompile GHC) to link with GNU gold.
You need in your .cabal
file:
library:
ghc-options: -optl-fuse-ld=gold
ld-options: -fuse-ld=gold
executable myExecutable
ghc-options: -optl-fuse-ld=gold
ld-options: -fuse-ld=gold
(Note you might want to pass these flags to stack
/cabal
/Setup.hs
on the command line instead of hardcoding them in the .cabal file in order to not reduce the portability of the package.)
For me it's 3.5x
faster, bringing down the total link time of a project from 150 seconds to 40 seconds.
Update: Link 10x faster with lld
See https://github.com/nh2/link-with-lld-example for a full example; key parts:
library
ghc-options: "-pgmP clang" "-pgmc clang" "-pgma clang" "-pgml clang" "-optl-fuse-ld=lld"
ld-options: -fuse-ld=lld
executable myExecutable
ghc-options: "-pgmP clang" "-pgmc clang" "-pgma clang" "-pgml clang"
ld-options: -fuse-ld=lld
Comparison of link time for the final executable link times my project:
ld 124 seconds
gold 36 seconds
lld 11 seconds
-dynamic
flag. It could easily speedup linking tenfold. – Vowelize-dynamic-too
, giving me both static and dynamic libraries. It would be great to have a minimal example project that shows if it really makes it faster. – Laboured-dynamic
GHC option.-dynamic-too
links both statically (slow, large executables) and dynamically (smaller executables, faster link times), so you don't get any speedup. – Vowelize--help
text) increased from160 ms
(static) to4.5 seconds
due to run-time linking. I will stick with static linking for now. – LabouredThe runtime performance costs of dynamic linking are substantial compared to those of static linking
. Note I have 100s of entries inlld
. Regarding speedup, link time seems to have gone down from 2.5 s per executable to 1.5, but that's not worth the increased startup time for me. – Laboured-fvisibility=hidden
and manually exporting all exported symbols. Maybe the dynamic loading startup time could be improved by using that. – Laboured