How To Compile Rust Code Faster: Compiler 101
summary
A 200k‑line Rust library has a 66s cold debug build; experiments target the front end and link stage for wins. Self‑profiling pinpoints slow type‑checking in an async_trait→BoxFuture use that drops ~7s when replaced. Enabling front‑end threading to eight threads trims ~30% (66s→45s). Trying Cranelift cuts ~4s for workspace crates. Tools used include cargo-llvm-lines to spot duplicated monomorphizations, cargo-udeps, and faster linkers like mold and wild (≈3s saved).
AI-written summary · about
chapters (21)
- 0:00Introduction and background
- 3:36What are compile times
- 5:23Why Rust compiles slowly
- 9:17Benchmark setup and project overview
- 10:22Compiler phases and IRs
- 14:57Sources of large IR generation
- 17:02Inlining and its trade-offs
- 20:52Generics and monomorphization
- 22:36Shared generics feature
- 24:24Parallel compilation with Z threads
- 25:47Optimization passes overview
- 27:55LLVM backend and alternatives
- 29:03Cranelift experiment
- 31:08Self-profile analysis tool
- 34:21Async trait pathological case
- 37:08Cargo pipeline and linking
- 38:34Splitting code into crates
- 39:19Dependency optimization tips
- 41:27Linkers and LTO options
- 42:10Alternate linkers comparison
- 43:33Dynamic libraries and future work
