? Use cargo check Instead Of cargo build Rumor has it that there's still a lot of low-hanging fruit. Work is also put into optimizing the LLVM backend. On top of that, Rust tracks compile regressions on a website dedicated to performance.
So make sure you use the latest Rust version: rustup update Thanks to their hard work, compiler speed has improved 30-40% across the board year-to-date, with some projects seeing up to 45%+ improvements. Making the Rust compiler faster is an ongoing process, and many fearless people are working on it.
If you're interested in all the gory details, check out this blog post by Brian Anderson. cargo does not explicitly mark the linking step, so many people add it to the overall compilation time. It "connects" your Rust binary with the system libraries. Linking: Strictly speaking, this is not part of compiling but happens right after.
LLVM: that's the default compiler backend for Rust, where a lot of the heavy-lifting (like code-optimizations) takes place.E.g., a function that takes an Into gets converted into one that takes a String and one that takes a &str. Monomorphization: this is the process of generating specialized versions of generic functions.Macros: Code generation with macros can be quite expensive.Overall, there are a few features and design decisions that limit Rust compilation speed: compile-time performance, and the Rust team nearly always (if not always) chose runtime over compile-time. One of those fundamental tradeoffs is runtime performance vs.
( Obligatory xkcd.) Compile-Time vs Runtime PerformanceĪs is often cautioned in debates among their designers, programming language design is full of tradeoffs. Why Bother?Īccording to the Rust 2019 survey, improving compile times is #4 on the Rust wishlist: Rust Survey results 2019. That said, above a certain project size, the compile times are. In general, comparing across different programming languages makes little sense and overall, the Rust compiler is legitimately doing a great job. This has advantages (more flexibility when tweaking the entire compilation process, yay) and disadvantages (higher overall maintenance cost and fewer supported architectures). On top of that, the Go compiler was built from scratch as a monolithic toolchain consisting of both, the frontend and the backend (rather than relying on, say, LLVM to take over the backend part, which is the case for Rust or Swift). For example, it lacks support for generics and macros. Wait a sec, slow in comparison to what? That is, if you compare Rust with Go, the Go compiler is doing a lot less work in general.
Tweak More Codegen Options Compiler Flags.Faster Incremental Debug Builds On macOS.Cranelift – The Alternative Rust Compiler.Disable Unused Features Of Crate Dependencies.Combine All Integration Tests In A Single Binary.Use Rust Analyzer Instead Of Rust Language Server.They are roughly ordered by practicality, so start at the top and work your way down until you're happy and your compiler goes brrrrrrr.
Compile times, however? That's another story.īelow is a list of tips and tricks on how to make your Rust project compile faster today. ? It is on par with the likes of C and C++ and sometimes even surpasses those. When it comes to runtime performance, Rust is one of the fastest guns in the west.