Description
The startup times of HLS can be quite slow, especially on cabal
projects.
One of the reasons is that we essentially call cabal
four times:
- What's the path of the ghc binary?
- What's the
libdir
of the ghc binary? - What's the
ghc-pkg
location of the ghc binary? - What are the compilation options to compile the package?
The first three commands boil down to roughly this:
cabal exec -- ...
cabal exec
can be quite slow though, as it sets up source-repository
s, runs the solver, etc...
On a perfectly set up HLS code base, cabal exec
needs quite some time:
$ time cabal exec -- ghc --version
Configuration is affected by the following files:
- cabal.project
- cabal.project.local
The Glorious Glasgow Haskell Compilation System, version 9.6.7
________________________________________________________
Executed in 1.10 secs fish external
usr time 842.53 millis 0.00 millis 842.53 millis
sys time 219.74 millis 1.28 millis 218.46 millis
So around 3 seconds are spent on figuring out the correct GHC binary, before we do anything.
The newly introduced cabal path
command on the other hand:
$ time cabal path
Configuration is affected by the following files:
- cabal.project
- cabal.project.local
compiler-flavour: ghc
compiler-id: ghc-9.6.7
compiler-path: /home/hugin/.ghcup/bin/ghc-9.6.7
cache-home: /home/hugin/.cache/cabal
remote-repo-cache: /home/hugin/.cache/cabal/packages
logs-dir: /home/hugin/.cache/cabal/logs
store-dir: /home/hugin/.local/state/cabal/store
config-file: /home/hugin/.config/cabal/config
installdir: /home/hugin/.local/bin
________________________________________________________
Executed in 34.27 millis fish external
usr time 16.10 millis 0.00 micros 16.10 millis
sys time 14.06 millis 965.00 micros 13.10 millis
and contains exactly the information we need: compiler-path
.
Likely, that's the only thing we need.
So, the idea is to update hie-bios
to use cabal path
if cabal
is recent enough (>= 3.14
) to shave off a couple of seconds of start up time on big Haskell projects.
Changes are exclusively to be done in hie-bios
, in particular https://github.com/haskell/hie-bios/blob/master/src/HIE/Bios/Cradle.hs#L578