LanguageCompilationSpeed

submited by
Style Pass
2021-05-20 19:30:10

One of the annoying things about programming in Rust is waiting for things to compile. “Why is Rust slow to compile” is a complicated question that has lots of moving parts that I won’t go into right now, but either way, rustc takes a while to do its work. But I’ve always felt like it was partially a problem of expectations. People used to fast-turnaround languages like JS and Python seem to complain about it loudest (even though I’ve had Typescript projects that take minutes to compile anyway). Meanwhile I don’t seem to see as many people used to C++ bitching about Rust’s compile times. Regardless of expectations though, everyone can agree on the fundamental issue: Faster compilation times are better. Nobody’s ever said “boy I wish I had to wait an extra ten minutes to see if this thing I made even works”. What people argue about is how MUCH better fast compiles are, and what the cost/benefit tradeoffs are.

So for a long time I have wanted to actually benchmark the speed of compiling Rust code vs. other programming languages, but it’s been stymied by one major problem: Lack of suitable benchmark code. A good benchmark for this sort of thing would be as direct a translation of a program from one language to another as possible by someone who is an expert in both, but in many ways Rust is unique enough to make that pretty hard. It has a type system much more like Haskell than C++, and the borrow checker encourages some patterns that are a little odd compared to both manual memory management and garbage collected laguages. A good benchmark would thus have to be a nontrivial program written in Rust and then translated to C++ as accurately as possible, or vice versa, and then one could still get tangled up in what is idiomatic code or whether the compilers are actually doing the same thing. A better benchmark would be several of these programs with different problem domains, with proper statistics and stuff, but frankly, I am not going to put that much work into trying to figure this out when I could be doing something actually useful instead.

Leave a Comment
Related Posts