I’m noticing slow incremental rebuilds in a project containing a large Tailwind.purs file. If I make a small edit to Example.purs (which includes Tailwind.purs), rebuilds take about 4 seconds. I’m wondering if there are some additional optimization opportunities where the unchanged contents of Tailwind.purs could be remembered between rebuilds.
Setup:
git clone --branch tailwind-purs https://github.com/milesfrain/halogen.git myApp
cd myApp
npm install -g purescript spago
# or if you prefer local installation:
# npm install
spago build
# slow initial build expected
Slow incremental rebuild (with or without edit to small Example.purs):
time spago build
[info] Installation complete.
[info] Build succeeded.
spago build 2.15s user 0.54s system 273% cpu 0.985 total
echo " " >> src/Example.purs
time spago build
[info] Installation complete.
Compiling Example
Compiling Main
[info] Build succeeded.
spago build 5.11s user 1.04s system 163% cpu 3.760 total
This is probably due to parsing externs too greedily. With the old JSON externs format this was necessary to get the compiler version, but with the new CBOR format we can get the version without parsing the whole file. We shouldn’t need to parse externs unless demanded.
That’s a good point, yes. If it depends on tailwind, then it’s going to have to parse the externs regardless. @milesfrain What version of the compiler are you using?
No, not quite. It’s not the source file which is being re-parsed, it’s the externs file. The compiler is already caching what it learns about Tailwind.purs, and the externs file is that cache; it contains information about the module’s interface, which is necessary for type-checking downstream modules. Parsing externs is unavoidable if a module which imports it has changed. If you’re looking for ways to speed things up, then the first thing to do is build a compiler with profiling enabled and see if anything jumps out.
I believe the answer might be somewhere in here, but I’m not sure whether I need the --work-dir flag. I recall that was mentioned before, but that’s supposedly unnecessary with stack 2.x (I have 2.3.1 installed).
No, it’s not really any different from any other Stack project. I think just stack build --profile followed by stack exec purs ... should do it. I find stack exec bash useful in order to set up a new shell with the compiler I’ve just built at the front of my PATH.
Geeze. I always forget those quotes! If only I updated to the latest-and-greatest spago v0.15.3 (released the day before) which has a note about this in the help text.
Profiling led straight to the issue. Now 2.5x faster with this fix.
I also had a pretty gnarly time getting my Haskell environment setup for this project, so I documented the steps that ended up working for me to help future users have a smoother experience.