My Rust Build Time Went From 4 Minutes to 32 Seconds
2025-06-26
The author's Rust website took 4 minutes to build, requiring a rebuild, copy, and restart for every change. To speed things up, Docker containers and cargo-chef were used for dependency pre-building, but with limited success. Using rustc's self-profiling and LLVM trace data, the author identified link-time optimization (LTO) and LLVM module code generation as major bottlenecks. Through a series of optimizations, including adjusting LTO levels, optimization levels, and breaking up large async functions, build time was reduced from 4 minutes to 32.3 seconds.
Development
Compilation Optimization