I was looking into optimizing a programs runtime and it started me down a rabbit hole of compile time performance. I have to admin I totally dont understand this or have a framework to really know what the trade offs are when wrtiing a program. I am just discovering more of this but I wanted to see if anyone had any blogs or ideas on how to know what the compile time performance is when writting Crystal?
As some fun numbers here is a breakdown of compiling crystal and my webapp on my laptop.
I assume this means Macro runs? Last time I checked macros themselves don’t actually have as big of an impact as people think. Macro runs on the other hand compiles and executes a Crystal program inline while compiling another program, which by its own nature can have a big impact. But it’s not the same thing as macros themselves.
However, macro runs result can be reused, so you only incur the impact on the first cold run of it.
If you squint, it’s probably possible but I’m not sure yet how much effort it would take. I say “if you squint” mostly because the unit the compiler cares most about appears to be more coarse than lines of code.
I tried at one point to instrument codegen to find out which methods were taking the longest to compile. I managed to get it working-ish (even included it in the output of --stats) but it seemed that the codegen time of a method also included the codegen times of all methods downstream of it, as well. There was also the fact that the compiler parallelizes compilation in forked processes by default. It becomes difficult to track pretty quickly.
So just tracking codegen is fraught, but total compilation time for a method also includes the semantic phase before codegen. I’m not sure how to track anything there yet, but since it determines which codegen needs to run at all it could really swing the metrics around.