Cranelift code generation comes to Rust

Compile-time performance vs LLVM

  • Multiple benchmarks show Cranelift cutting total compile time by ~17–30% on various projects, including Rust itself; CPU-time savings in one detailed measurement were ~40%, with faster incremental rebuilds too.
  • Some users see only marginal improvement in certain setups until cache effects (like sccache + NAS) are accounted for.
  • It’s emphasized that compile time includes parsing, type-checking, MIR, and linking; codegen is only a part, so Amdahl’s Law limits gains.
  • Faster linkers (LLD, mold) further reduce build times, and combined with parallel frontend work, Rust builds could speed up substantially.

Runtime performance / optimization quality

  • Older research showed Cranelift compiling much faster but producing significantly slower code; commenters say Cranelift has changed a lot since then.
  • Current expectation: Cranelift code is often 10–30% slower than LLVM, sometimes close, and unlikely to systematically match the best LLVM/GCC output.
  • Cranelift is positioned as “fast enough for dev” rather than a drop-in for high-performance release builds.

E-graphs and optimizer design

  • Discussion contrasts equality-graph-based optimization with traditional pass pipelines.
  • E-graphs avoid phase-ordering issues by keeping multiple equivalent representations and choosing later, but can grow large; Cranelift uses a constrained, acyclic variant with eager rewrites to stay fast.
  • Some commenters are enthusiastic about e-graphs as the future; others highlight unresolved practical issues like extraction strategies and memory growth.

Incremental builds and caching

  • Several users report large wins (often 2–4× faster) for incremental dev builds, especially when combining Cranelift with a fast linker.
  • There is interest in tighter integration with sccache and more granular caching (e.g., MIR-level) to avoid redundant work for non-semantic changes.
  • Question raised whether this overlaps with Rust’s existing incremental compilation; unclear how far current mechanisms go.

ABI, backends, and ecosystem

  • Mixing Cranelift and LLVM within the same compiler version is said to be safe because ABI decisions live in shared, backend-agnostic code.
  • Platform support is incomplete: Windows works; macOS arm64 has calling-convention complications and is not yet fully supported.
  • Some want to use Cranelift for non-Rust languages; options mentioned include textual IR, Rust library bindings, or alternatives like QBE.

Superoptimization and “maximal” optimization

  • Thread explores why superoptimizers aren’t standard: huge compute cost, diminishing returns, practicality limited to tiny hot loops, and complexity of correctness proofs.
  • Consensus: today’s compilers improve performance slowly over time; allocating “unlimited” CPU for builds likely yields modest real-world gains.

Overall sentiment

  • Many are excited about faster debug and incremental builds and see Cranelift as a major step for Rust ergonomics.
  • Some criticize the article as overly positive and stress that LLVM remains superior for peak runtime performance and broad platform maturity.