My Haskell project spends lots of time in Linking dist/build/myapp/myapp ...
and also in loading shared libraries when executing TemplateHaskell
code.
I suspect this is because ld
is slow.
How can I improve link times by switching to the gold
linker?
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:(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:
Comparison of link time for the final executable link times my project: