I know rustc has a reputation for slow compile times, but I wanted to find out how my experiences compare to others.
I have a ~8,000 line Rust project that, on my little laptop, takes about a minute to compile on 1.22.1, and 3-4 minutes to compile on nightly. Incremental compilation may take that down 10% or so.
If I compile a C project of similar functionality and ~14,000 lines of code, it compiles in 6 seconds. And, most significantly, if I just touch a single file and recompile the project, it compiles in less than half a second.
Is this comparable to what other people are experiencing? My Rust project does use generics pretty heavily and uses macros to generate a lot of code, so that ~8,000 line statistic is misleading, but still, this seems very slow to me. I consider the nightly compiler basically unusable: especially on a project of this relatively small size, I have to be able to make small changes and test them very quickly. 4 minutes is bonkers.
Which C compiler are you using? Not sure what the right magnitude difference should be (template heavy C++ code is probably a better comparison than C), but you can try running cargo check to do typechecking. This won’t help you run the program but can serve as a quick(er) compilation feedback loop. If you’ve tried it already, how long does that take?
There’s a way to make rustc spit out timing info per phase, so can probably jump down to that level to see where the bulk of the time is spent (my hunch is LLVM is a significant portion).
It seems that a lot of time is being spent in "translation item collection," and a search reveals lots of discussion about excessive times here for generic code (like this).
Ugh. Just a few weeks ago I had an issue that was giving me 20+ minute compile times. That one I reported and it was quickly fixed. But this current issue has been under discussion for a year, has not been resolved, and has just been reduced in priority.
I take it you have similar type layering code as in the github issue you linked? Curious if sprinkling a Box here and there would cut it down. But yeah, otherwise not sure what to suggest given this is a known issue.
Well, there's nothing in my code that chains calls in an obvious way like the linked issue. But my intuition is I'm winding up with a similar effect. Yes, I guess I could probably use trait objects in a couple places to address this. I'll experiment with that. Thanks again.