GHC is slow on first :main
When loading certain projects into ghci, the first call to
main after a
:l or a
:r will take a few seconds until the
main is actually executed.
This makes live reloading in IHP very slow. E.g. when a user changes some haskell code in an IHP project, the IHP dev server will stop the current app in ghci and trigger a
:r. The IHP dev server watches for a message such as
Ok, 199 modules loaded. and then triggers a
:main. This call to
:main now takes a couple of seconds to execute, even though ghci already told is that it has reloaded all necessary files.
Here's a video showing the problem:
Main entered message appears as expected, but there's a long delay between when I enter
main and when the message appears. The
putStrLn "Main entered" is the first operation in that module:
main :: IO () main = do putStrLn "Main entered" IHP.Server.run config
Steps to reproduce
This problem also happens with the IHP repo itself, so we can use that to reproduce it.
To load IHP into ghci, you need to install nix and devenv.sh first.
devenv.sh is installed, run
cachix use digitallyinduced to enable our binary cache for a faster build time.
Now you can reproduce it by running these commands:
# Clone the repo git clone https://github.com/digitallyinduced/ihp.git cd ihp # This will enter a shell with all dependencies nix develop --impure # Run ghci ghci :l Test/Main.hs # => Ok, 152 modules loaded. main # ... now it takes a few seconds until the app starts up
main should directly start the app, without a delay of a few seconds.
- GHC version used: 9.4.4 + 9.6.2
- Operating System: macOS (This problem might be mac specific, I've not seen similiar behaviour on linux computers)
- System Architecture: x86_64
- Project Size: This problem seems to only appear in projects with more than a few modules. On a fresh IHP project with 20 modules, the
:mainis typically instant.