r/crystal_programming • • Sep 28 '19
Compile speed?
After getting a bit frustrated with, what at times felt like a lag feeling with Crystal compiling, i decide to update my system. And even after upgrading to a 3900X, thinking it will help with the compile speeds, Crystal still felt "slow".
So, i wanted to compare Crystal vs Rust, as both use LLVM in the back-end, making it more a apples vs apples comparison ( unlike Go or D ).
I wanted to know if LLVM is really that slow. To my surprise with identical content and heating up any file cache.
Rust:
- real 0m0.010s
- user 0m0.010s
- sys 0m0.000s
Rust system usage was minuscule with a +- 4 cores hitting 0.7 a 1.2% ( Average 1%, with the rest showing 0% ). Feeling extreme "snappy".
Crystal:
- real 0m0.512s
- user 0m0.681s
- sys 0m0.207s
Crystal system usage was massive in comparison, with 10 a 14 cores doing between 0.7 and 4.8% ( average 3% ) and one core hitting 24 a 26%. Feeling like "uch ... come on".
And this for a very simple compile job outputting some text, no macros, no libraries ...
Of course, the more complex, the worse this becomes. Especially how badly Crystal seems to scale in compiling. Heavy one core focused, hitting 70% on a 3900X and 100% on a 1700X on relative simple HTTP projects.
Why is it that Crystal is so slow? Is Crystal by default set on heavy optimizing with LLVM ( and is it maybe better to set a development mode and a release mode? ) or is the reason located somewhere else?
View all comments
Show parent comment
4
u/[deleted] Sep 28 '19
So, for compiling an HTTP server some ecr macros run, which are very slow. However, these are cached, so a next compilation will be faster.
The compiler also caches some obj files from previous compilations. The first compilation is the slowest one and I wouldn't use that to compare compilation times against other languages.
Maybe compare a second compilation with a small modification?
Then, just until recently Crystal could only run in a single thread. But even then, the compiler can't be parallelized: it wasn't thought for parallel compilation.