← back

Speeding Up Rust Compilation

Practical techniques for 2-4x faster development builds

Published December 21, 2025

The Problem

Rust compilation is notoriously slow. The bottleneck lies in two distinct stages:

  1. Frontend (rustc): parsing, macro expansion, type checking, borrow checking
  2. Backend (LLVM): optimization and code generation

To identify which stage is your constraint, run cargo check. If it's sluggish, the frontend is your bottleneck. If checks run quickly but builds lag, the backend needs attention.

Backend Optimization

The backend offers several practical speedup opportunities:

1. Cranelift Code Generator

Cranelift is an alternative compiler backend that prioritizes compilation speed over output quality. It delivers approximately 2x faster code generation for development builds, though with slower runtime performance.

Installation:

rustup component add rustc-codegen-cranelift-preview --toolchain nightly
export CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift

Best practice: Use Cranelift for development iterations, ship with LLVM for production.

2. mold Linker

A faster replacement for the default linker, achieving 2-5x linking speedups.

Configuration in .cargo/config.toml:

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

3. sccache

A compiler output caching tool that improves rebuild performance by storing compilation results on disk. Particularly valuable for CI pipelines.

Note: The OS page cache already keeps hot entries in RAM automatically, so local development gains may be modest.

4. Aggressive Dev Profile

Optimize your development profile for speed in Cargo.toml:

[profile.dev]
opt-level = 0           # No optimization
debug = false           # Disable debug symbols
incremental = true      # Enable incremental compilation
codegen-units = 256     # Enhanced parallelism

Frontend Reality

There's no quick fix for frontend speed. Parallel frontend compilation is years away. The practical mitigations:

Why Go Compiles Faster

Rust prioritized safety and zero-cost abstractions over compile speed. Go made the opposite choice: compilation-first design with file-level parallelism, simpler grammar, and custom compiler infrastructure. These are fundamentally different design philosophies.

Combined Approach

Using Cranelift, mold, sccache, and an aggressive dev profile together typically achieves 2-4x faster development builds. This is realistic expectation — not a magical 10x improvement.

Practical Workflow

Key Tradeoffs

Reality Check

Cranelift produces faster compile times but significantly slower runtime performance. Never ship Cranelift-compiled binaries to production. This is a development-only optimization.

Core Insight

The frontend bottleneck has no quick technical fix. The only solution is architectural: write less code, minimize dependencies, avoid heavy macros. The backend bottleneck has proven tools that deliver real speedups.