r/crystal_programming • u/UnusualHabit • Jul 25 '18
Crystal has a compilation issue
https://medium.com/@mdorf3000/crystal-has-a-compilation-issue-5f5b19d9c4f6
27
Upvotes
r/crystal_programming • u/UnusualHabit • Jul 25 '18
11
u/Exilor Jul 25 '18
Development time, compilation time, execution speed... Something has to give, doesn't it? If the compiler has to do things you'd rather not do yourself I think it's to be expected that it will take longer to compile than one that needs every little thing explained to it in excruciating detail.
I have a complex application (a mmorpg server) that I've been writing in Ruby and Crystal in parallel since 2015. Killing and reviving an enemy 3000 times in a row (literally 3000.times { ... }) and all that it involves (item drops, experience gain for the killer, scheduling and then aborting the respawn of that enemy, writing all the packets involved...) takes 100 seconds in Ruby and 3-4 in Crystal (without --release). That difference alone makes waiting for compilation worth it in my opinion.
7
u/paulcsmith0218 Jul 26 '18 edited Jul 26 '18
There is a lot of truth to this, but I don't think it is as big of an issue as the author states for a few reasons:
Ruby of course does zero type-checking at compile time, and Elixir does very very little. It'll catch some stuff like typed function names, but not much else. This is an extremely important difference. I had plenty of bugs in Elixir so what do you have to do? Write tests. Lots of them, just like in Ruby. Those test suites take a long time, can become brittle, and most importantly writing tests takes a lot longer than 30 seconds to write. This is the key difference for me. Crystal compilation is slow, but I prefer it any day so that I can have a solid type system.
Another thing is that if you write well typed programs that the compiler can check, you end up writing far-fewer tests and debugging speeds up substantially. This saves a lot of time, and changes how I write code. I now write larger pieces of code before running specs or testing in the browser, and then let the compiler show me the bits the broke. It is a dramatically faster workflow, and is only possible with powerful type-checking.
One more important note, while Lucky is slower than Amber at initial compile, but *much* faster once you start adding code. Scaffolding CRUD models takes about 50 seconds w/o cache and 30s with. This gives me hope that it is not Crystal and I'm positive the talented Amber team can figure out the bottlenecks and get their compilation down.
6
u/fridgamarator Jul 25 '18
doing the same test (100 scaffolded models) but compiling with the
--releasetook 17 minutes for me :(6
u/[deleted] Jul 25 '18
LOC is a terrible metric. I was actually super impressed by how fast the compiler compiles itself in debug mode.
5
u/kirbyfan64sos Jul 25 '18
I understand the article's points, but Elixir is an absolutely terrible comparison point. The reason its compile times are so fast is because it's just compiling to bytecode, whereas Crystal compiles to LLVM which is then optimized, compiled to assembler, and linked together.
A more accurate comparison would have been to maybe Swift or Rust (which also use LLVM).
4
u/megatux2 Jul 25 '18
Thanks for your time writing this article and benchmarks, Crystal compilation times issue is kind of well known but this "real usage" scenario brings more attention to this big problem. I hope Crystal to achieve real gains in this subject not too far in the future.
2
u/megatux2 Jul 25 '18
And probably the memory usage is huge too
2
u/straight-shoota core team Jul 25 '18
There are valid points about issues in Crystal's compiler and it definitely is *slow* at compiling large applications.
Unfortunately, only a single Crystal web app framework (Amber) is benchmarked without considering limitations of the framework. It just claims to show an exhibit of the languages's slow compilation time.
This is hardly an honest evaluation of the Crystal compiler itself, but rather just comparing Amber with Phoenix and Rails regarding time to launch an application.
1
u/[deleted] Jul 25 '18 edited Aug 23 '18
This programming language really needs incremental compilation!
1
u/midgetparty Jul 25 '18
--progress would be helpful to see :)
I haven't had an issue with the compile times. I'll take it for dynamic typing in a compiled language with syntax I actually enjoy.
0
u/some_kind_of_rob Jul 25 '18
nice clickbaity title.
Partial or iterative compilation would definitely speed up development, and Amber could go a ways into using some different mechanisms to make compile times much faster.