Rust compilation is impossible to solve for some reason.
I have a 4k line project that depends on serde-json, xxhash, crossbeam and rand.
It takes several seconds to compile in release mode.
This is insane compared to my 20k line project in C++ which compiles everything and runs all tests in 0.7 seconds.
The C++ project doesn't depend on libc or any external libraries but that is not a practical option in rust.
I tried bunch of different options and actually removed some dependencies but it seems like it is not possible to get the rust program to compile fast.
Does anyone know why it is this slow comparatively?
serde, crossbeam, and rand all involve generics so you may be getting a decent amount more code than 4k lines after macro expansion (aka #[derive(Serialize, Hash)).
you might also be able to drop crossbeam for stdlib types and rand for much smaller random library if you don't need it's comprehensive features.
cargo's release profile also uses opt level 3 and thin-local lto by default. Whether you need those is up to you, hard to say more without knowing your project!
but yes it is somewhat easy to allow rust projects to creep up in compile times especially with how easy it is to bring in big useful libraries that often come with a lot of features. disabling features where possible is the go to if you have big dependencies.
It's interesting how much of the next gen compiler improves borrow heavily from logic programming. I don't know if any other compilers that have made the connection to logic programming as explicit as rustc.
My C compiler rcc uses a handwritten solver in -O3 to solve contracts. I've tried z3 and others, but my own was way faster, no overhead. It's like MySQL vs sqlite in-proc.
The article is great but actually lacks data on overall performance. It looks like the big focus was handling pathological performance cases, which they have done a great job on. Overall though this looks like a mild performance regression (~6%) for the compiler based on an October test [0]
I like that Rust is principled about correctness, but as a mostly moved on long suffering C++ developer it’s disappointing the replacement suffers from the same poor compilation performance. At least rust has a culture of tracking and working on perf even if philosophically the community puts it low down their list.
This is still work in progress, to be fair. Those results are already outdated, a number of optimizations landed since then. It'll probably take a bit more time to close the gap, but we expect the final result to be mostly similar to the old solver or faster. I'll also caveat that our benchmark suite is skewed towards pathological cases (when it comes to the type system code), so it doesn't necessarily indicate performance on average program.
I think there is a little error in the code snippets near the caching section start where it claims variables are swapped but they are not? Though maybe I have just misunderstood something.
I have a 4k line project that depends on serde-json, xxhash, crossbeam and rand.
It takes several seconds to compile in release mode.
This is insane compared to my 20k line project in C++ which compiles everything and runs all tests in 0.7 seconds.
The C++ project doesn't depend on libc or any external libraries but that is not a practical option in rust.
I tried bunch of different options and actually removed some dependencies but it seems like it is not possible to get the rust program to compile fast.
Does anyone know why it is this slow comparatively?
you might also be able to drop crossbeam for stdlib types and rand for much smaller random library if you don't need it's comprehensive features.
cargo's release profile also uses opt level 3 and thin-local lto by default. Whether you need those is up to you, hard to say more without knowing your project!
but yes it is somewhat easy to allow rust projects to creep up in compile times especially with how easy it is to bring in big useful libraries that often come with a lot of features. disabling features where possible is the go to if you have big dependencies.
Of course any theorem prover will have an even deeper connection to logic in it's compiler and we've been building those since the 70s.
Which other compilers do you know?
Swift compilers when doing the same?
Haskell compilers when doing the same?
Idris, F*, Dafny, Koka,..... compilers doing the same?
I like that Rust is principled about correctness, but as a mostly moved on long suffering C++ developer it’s disappointing the replacement suffers from the same poor compilation performance. At least rust has a culture of tracking and working on perf even if philosophically the community puts it low down their list.
0 - https://perf.rust-lang.org/compare.html?start=b5427502dab50c...
I think there is a little error in the code snippets near the caching section start where it claims variables are swapped but they are not? Though maybe I have just misunderstood something.