4 ms·
I don't know a lot about compilers but as far as I can tell from a compilation complexity standpoint Rust is C++ on steroids. Like C++ (and unlike higher level
by simias 8y ago
I don't know a lot about compilers but as far as I can tell from a compilation complexity standpoint Rust is C++ on steroids. Like C++ (and unlike higher level ML languages) Rust does most of the type system heavy lifting statically at compile-time. That results in potentially faster and simpler machinecode with fewer runtime dependencies but it also means that the compilation "tree" can become extremely complex since you need to resolve all types at compile-time and emit code for it. You can't just emit dynamic code that will dispatch at runtime.
Heavily templated C++ code is notoriously slow to compile so it's no surprise that heavily genericized Rust code doesn't fare much better.
On top of that Rust builds one crate at a time basically, it's not like C where you typically have plenty of smaller compilation units that are black-boxes to one-another. C++ has the same compilation model but as mentioned above templates need to be resolved completely at compile-time so all templated code ends up in headers and therefore in copy/pasted by the processor every compilation unit it's used in.
And then after all that in Rust you have the borrow checker which probably ads a non-negligible runtime overhead.
I agree that it's an interesting evolution as far as programming languages are concerned. I consider that Rust is overall superior to C but at the same time in the seventies nobody could have run a Rust compiler on anything more than a Hello World. Meanwhile I've just compiled (with optims) an auto-generated C file of about 20k lines almost instantly on my 2018 computer.
- pjmlp 8y agoYou can get reasonably fast compile times in C++ with a mix of incremental compilation, incremental linking, binary libraries and if using clang or VC++, experimental modules support. Still slower than compiling Ada, Delphi, Eiffel, D code, though.