7

I'm currently using Stack to build a project, which totals about 80 modules and 13,000 lines of code. Currently, compilation takes about 3 minutes for a minor change in my types files, which is unacceptable -- it prevents me from rapidly testing my code via stack ghci. It also significantly slows down a number of things: for instance, pair programming with peers or consulting with experts.

I would like to be able to figure out why compilation is taking so long, and what I can do to speed it up. Is there some way to profile compilation times?

Additionally, how can I tell whether it is stack or ghc that is slow?

I know about setting -O0, though this does not seem to help compilation times. I also know that TemplateHaskell and Typeclass Resolution can take a while -- is there any way I can get better resolution on how long these are taking?

Note: i have seen Speed up compilation in GHC, but that was from 2013, and hdevtools currently does not work on my setup.

11
  • You mention "compilation" several times but you also say you are using ghci. Are you compiling or interpreting? It makes a big difference. Compiling with -O0 is not the same as interpreting, and if you are interpreting, then the -O switch does nothing anyways. What is your compilation time from scratch, i.e. how does it compare to the 3 minutes? If you make a change at the module at the top of the hierarchy, then it will recompile every single module - in general it couldn't tell whether it has to or not. Feb 13, 2016 at 3:25
  • Also, TH does indeed cause massive slowdowns past a few hundred lines of generated code or so. There is no way around it, other than to improve the implementation of TH. You can sometimes speed up TH by reducing the number of splices (i.e. moving multiple splices into a single splice). If you are working on a module with a lot of TH, but not changing that TH code, consider moving the TH to a separate module. Feb 13, 2016 at 3:28
  • well, I sometimes compile (stack install), sometimes I use stack ghci and its set up to autoload my entire project. They both take about the same time. My bad for conflating the two. Feb 13, 2016 at 3:53
  • 1
    @TimothyChu if you found the solution to your question, you should post it as an answer so this question doesn't remain unanswered...
    – sclv
    Mar 4, 2016 at 3:10
  • 1
    Depending on the module graph of the package, I sometimes see handy speedups when I add --ghc-options -j3 to stack build.
    – sjakobi
    Nov 23, 2016 at 18:15

1 Answer 1

2

In case this question is still relevant, you could try this:

stack ghci --fast --no-build --ghc-options="-fbyte-code"

IIRC using this got me the quickest results with stack ghci.

If this doesn't help enough, you could look in the direction of --ghc-options="-dshow-passes". I myself am also looking in this direction currently to try to speed up a build/ghci-reload.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.