Speeding up Haskell stack project compilation and git branches
Asked Answered
E

0

6

I cannot change GHC's compilation times, but I can control the environment in which things are compiled. What can I do with git and stack to minimize downtime due to (re-)building?

Haskell stack caches compiled dependencies in the .stack-work directory, and it great for working on one thing at a time. However, I find myself switching back and forth between branches. I've done git checkout in place, and perhaps some of the .stack-work cache is usable. But I greatly prefer git worktree to get a copy of a branch in a different directory altogether. Worktree is especially hard on build times as each worktree directory will have its own .stack-work, and therefore must download/configure/compile/install its own dependencies instead of using existing ones.

I've been doing some reading about Nix and Haskell, but since stack creates its own cache, it ignores whatever Nix has compiled and installed. From what I've read, I really want Nix to handle dependencies and stack to handle my personal code. I get great benefit from stackage and stack solver, so I do not want to give them up. But when I see a screenful of "unregistering" messages when running stack build --only-dependencies && stack ghci, I know that I've got at least 10-15 minutes before I get a prompt.

Many thanks!

Earlearla answered 5/7, 2017 at 15:31 Comment(3)
Concerns like these contribute to the fact that I still use Cabal most of the time (and without sandboxes) instead of Stack... probably unjustified though, for cannot Stack also keep a system-global cache?Postboy
From what I can tell, the only system-global 'cache' stack keeps is GHC installs in ~/.stack and binary installs (like alex and happy) in ~/.local/bin. Do you use Cabal for projects with dozens of dependencies, and if so, do you draw from Stackage releases or something else?Earlearla
I mainly draw from good old Hackage (as cabal install defaults to), which works fine most of the time and generally avoids compiling any package over again if it has ever been installed before on the system. When there's a conflict (the kind that Stack was written to avoid), I'll generally clone the offending package straight from Github, tweak the dependencies as needed, and move on.Postboy

© 2022 - 2024 — McMap. All rights reserved.