Skip to content

Speed up startup times: hie-bios should use cabal path #4562

Closed
@fendor

Description

@fendor
Collaborator

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-repositorys, 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

Activity

added theissue type on Apr 17, 2025
alexfmpe

alexfmpe commented on Apr 17, 2025

@alexfmpe

I'd like to have a go at this

alexfmpe

alexfmpe commented on Apr 18, 2025

@alexfmpe

See haskell/hie-bios#458

So around 3 seconds are spent on figuring out the correct GHC binary, before we do anything.

Likely, that's the only thing we need.

Am I missing something? cabal path only seems to replace the first of the 3 cabal exec commands so that would be 1 second no?

fendor

fendor commented on Apr 19, 2025

@fendor
CollaboratorAuthor

The other two commands should be unnecessary with the ghc path from cabal path as we get the path from the wrapper and not the raw executable path, so the paths are set up correctly.

So we dont need to generate our custom ghc shim with the ghc-pkg executable and the libdir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @alexfmpe@fendor

    Issue actions

      Speed up startup times: `hie-bios` should use `cabal path` · Issue #4562 · haskell/haskell-language-server