I don’t usually run specs with -O1, but that does take an exceptionally long time to compile. I let it run for 27 minutes on my machine before killing it.
âžś captcha git:(master) time csp -O1
^C
crystal spec -O1 24.24s user 0.60s system 1% cpu 27:48.08 total
Without -O1, it takes significantly less time even on a cold compilation:
âžś captcha git:(master) crystal clear_cache
âžś captcha git:(master) time csp
...
Finished in 557.48 milliseconds
3 examples, 0 failures, 0 errors, 0 pending
crystal spec 10.23s user 0.76s system 126% cpu 8.715 total
Even --release wasn’t bad:
âžś captcha git:(master) crystal clear_cache
âžś captcha git:(master) time csp --release
...
Finished in 101.54 milliseconds
3 examples, 0 failures, 0 errors, 0 pending
crystal spec --release 14.58s user 1.38s system 99% cpu 16.127 total
Since the second run took 2 seconds, I suspect the cache mechanism is involved. Adding the -O1 option would likely require recompiling many standard library classes into objects again. However, I’m not sure if that alone explains the slow compilation.
llc -O1 only runs backend optimizations like instruction selection and register allocation. It does NOT run middle-end optimization passes, which is why it’s fast.
Crystal’s compiler runs the full LLVM optimization pipeline via LLVM.run_passes with “default”. This is equivalent to running opt -O1 first, then doing what llc does.
So it’s hard to tell which part of the pipeline is actually slow.
In fact, llc seems to be taking longer.
My understanding of compiler internal is fairly limited. And investigation is based entirely on AI support.
Can anyone reproduce the long object-file generation time from .bc files, and explain why?
Just for clarify, because crimage use Slice instead of StaticArray in this recent commit, so, if someone want to reproduce, need use code before this commit instead.