Crystal builds and runs programs much slower than expected on my system.
The program tested can be replicated by running crystal init hello and putting puts "hello world" into src/hello.cr and trying to run it.
I have seen others build programs much more complex much faster using crystal on their systems and other languages like rust and go compile programs much faster on my system.
Here are the benchmarks from hyperfine using command hyperfine --warmup 3 "crystal ./src/hello.cr" --export-markdown ./Benchmarks.md
Command
Mean [s]
Min [s]
Max [s]
Relative
crystal ./src/hello.cr
5.001 ± 0.329
4.604
5.501
1.00
( s stands for seconds )
I am not sure what causes this and i am very new to crystal, any help would be nice.
This is somewhat of a known âissueâ. See Incremental compilation exploration for some related discussion on why its a bit of a problematic thing to solve.
But itâs also relative to your hardware, as its pretty darn quick for me. I know the compiler really likes having fast single core perf, which can have a big impact like youâre seeing. So really comes down to what your system is .
After using Crystal for a while, you will get used to it, considering the programming efficiency brought by Crystal, it is worth it.
Even, for Crystal only, you should purpose a new beast PC, that is how i did it, although only a AMD 7840hsïŒ but the current development experience is acceptable.
Itâs pretty much impossible to draw any conclusions from your benchmark results, without any information about the system youâre running this on. Comparison with performance of other compilers (or any kind of benchmark really) could also provide some context whether the performance is expected or not.
Here is my full system information.
i posted the benchmark here because i felt it was an accurate measurement but my main concern is that compiling programs takes 5 seconds on my hardware.
Crystal taking 2.5 times longer than clang seems quite reasonable.
The ratio is similar on my system. But the absolute times are significantly faster: 278ms and 908ms.
So it doesnât seem thereâs anything wrong with the Crystal compiler in particular. Your system performance seems to be very poor for some reason. The i5-8250U is a bit dated of course, but I would expect it to have more punch than what youre measurements show.
i5-8250U is a really bad(slow) CPU compare to Intel 12??? or 13??? or AMD zen3, zen4, my bet you really should update yourâs hardware for to use Crystal.
I am not in the position to update my hardware right now (most things are working well enough), so i probably will not be able to learn/use crystal. I donât think the laptop is too old, (4 years) but oh well.
It seems most people have a good experience but my specific hardware seems to just not work well with it.
You have similar âsingle core performanceâ as my Ryzen and my crystal hello.cr takes about 2 seconds (or less) . It looks like itâs a laptop:
try to find out if a thermal throtling isnât the problem of worse than expected performance - if so, there may be a thick cohesive brick of dust in the fan from all the years :) :)
also make sure the CPU is not in some power saving mode (try tracking the current core frequencies during the benchmark - is it getting to maximums near 3.4 GHz)?
Just wanna pop in to say an i5-8 is absolutely not a slow cpu and we should not be relying on new absurdly fast hardware to forget crystalâs compile time speeds - that alienates all those who canât buy expensive hardware.
(5 seconds is also normal for me on windows, though it tends to be much faster in wsl)
True⊠But as one whose experience goes back to the 68000 (at a blazing 7.14Mhz), Iâll say thereâs also a matter of mindset. What is âfast compilationâ anyway? Sure, the Go compiler is much faster, but if I take half the time in Crystal coding an equivalent program, thereâs room for waiting for the compiler.
(Not that I would mind a speedup of the compilerâŠ)
So, yeah, I know itâs a bit rough in the beginning, but I think it pays off in the long run.
Note: on UNIX (and thus WSL) we can use fork to do the LLVM codegen in multiple processes, which we obviously canât on Windows. This can explain some (maybe most?) of the âslower to compile on windowsâ behavior (check with crystal build --stats).
An alternative would be add a crystal codegen command instead of forking, and to stream the LLVM IR from the main process to the codegen processes (similar to how its done in MT). That would be Windows compatible.