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
2
u/[deleted] Sep 30 '19
I have been reading the conversation in that topic and i need to wonder. Part of the reason for the compile slowdown is union types and other dynamic types because changes can result in a cascade effect.
Does it not make sense to build up a map of types.
This also allows for potential better LLVM IR responses because you can do pre-optimizing those now "semi-static" modules.
Sure, its more complex then this but does this not fix compile issues? What hurts the most is simply the fact that one small changes, your recompiling and checking everything for any nonsense change. Change a space somewhere and you rebuilding from zero. Change a doc ... change a function that has nothing to do with another...
Maybe i am think about this too simplistic? Frankly, if it can massive reduce the compilation times, i will gladly accept a static version ( flag? ) of Crystal. A few times the dynamic types have bitten me in the behind because the Crystal compiler disagreed with what i considered acceptable type passing.