Fast Rust Builds (2021)
10 months ago
- #Rust
- #Build Optimization
- #CI/CD
- Rust code is known for slow compilation, but projects like rust-analyzer show it's possible to maintain reasonable build times with care.
- Build times are crucial for productivity, acting as a multiplier on development speed and affecting mental flow and context switching.
- The 'silver bullet' for managing build times is continuous attention and optimization before they become a problem.
- CI time is a valuable metric for build performance, offering standardized feedback and encouraging healthy practices like using merge robots (e.g., bors).
- Effective CI caching strategies focus on rarely changing dependencies rather than the entire target directory to optimize build times.
- Reducing dependencies and critically evaluating each one's necessity can significantly decrease build times.
- Tools like `cargo -Z timings` and `cargo llvm-lines` help profile and optimize compilation by identifying bottlenecks and redundant instantiations.
- Architecting Rust projects with a clear crate dependency graph can enhance parallelism and reduce compilation times.
- Avoiding excessive use of procedural macros and generics at crate boundaries can prevent unnecessary compilation overhead.
- Strategies like thin generic wrappers around non-generic implementations and minimizing the number of final artifacts can further optimize build times.