Building Rust binaries in Docker repeatedly is slow due to full rebuilds and heavy LTO and LLVM optimizations.
Using cargo-chef caches dependencies but the final binary still takes minutes because rustc’s codegen and link-time optimizations dominate.
Rust’s self-profiling (-Zself-profile) and LLVM trace flags help identify hotspots in codegen, notably LTO and per-function optimization passes.
Disabling LTO and debug symbols, lowering opt-level for the final crate, and tuning LLVM inlining thresholds can cut compile times significantly.
Further speedups come from splitting large async functions, boxing futures to hide complex state machines, and avoiding repeated generic instantiations.
Combining these techniques reduced a Dockerized Rust build from ~175s to ~32s, showing practical ways to speed up slow Rust compile times.
Get notified when new stories are published for "🇺🇸 Hacker News English"