A smart Cargo wrapper that automatically stacks every available optimization: Cranelift (fast codegen) → mold/lld (fast linking) → LLVM (max optimization) → PGO/BOLT (profile-guided).
rustm wraps cargo and automatically applies the optimal combination of:
| Layer | Optimization | Impact |
|---|---|---|
| Codegen | Cranelift for dev, LLVM for release | 2-5x faster dev compiles |
| Linker | mold (5-10x) > lld (2-5x) > default | 5-10x faster linking |
| Linker Algo | ICF, relaxation, section ordering, GOT/PLT | 3-15% smaller/faster binaries |
| Profile | target-cpu=native, LTO, codegen-units, strip | 10-30% faster runtime |
| PGO | Profile-Guided Optimization | 10-30% runtime speedup |
| BOLT | Post-link binary optimization | 5-15% on top of PGO |
| Cache | sccache distributed compilation cache | 30-70% faster incremental |
git clone https://github.com/mew-sh/rustm.git
cd rustm
cargo build --release
cp target/release/rustm ~/.cargo/bin/cd your-rust-project
# Initialize config
rustm init
# Build with default profile (dev-fast)
rustm build
# Build release — fastest binary
rustm build --release --profile fastest
# Ultra-fast dev builds with Cranelift
rustm build --codegen-backend cranelift
# Check system for optimization opportunities
rustm doctor
# View available profiles
rustm profilerustm integrates rustc_codegen_cranelift as an alternative codegen backend for 2-5x faster dev builds.
| Aspect | LLVM | Cranelift |
|---|---|---|
| Pipeline | MIR → LLVM IR → ~120 passes → SelectionDAG → MC | MIR → CLIF IR → RegAlloc → ISel → MC |
| Codegen speed | Baseline | 2-5x faster |
| Memory usage | Baseline | 40-60% less |
| Binary performance | 100% (optimal) | 80-95% (good) |
| Auto-vectorization | Full (AVX2, NEON, SVE) | Limited |
| LTO support | Full (thin/fat) | None |
| Debug info | Full DWARF | Basic DWARF |
| Best for | Release builds | Dev iteration |
# rustm automatically selects the best backend per profile:
# dev-fast, dev-check, dev-cranelift → Cranelift (if available)
# release, fastest, release-max → LLVM
rustm build # Auto: Cranelift for dev
rustm build --release # Auto: LLVM for release# Force Cranelift (fastest compiles)
rustm build --codegen-backend cranelift
# Force LLVM (best optimization)
rustm build --codegen-backend llvm
# Config: rustm.toml
[build]
codegen_backend = "auto" # "auto", "cranelift", "llvm"# Requires nightly Rust
rustup toolchain install nightly
rustup component add rustc_codegen_cranelift --toolchain nightlyrustm applies optimizations based on mold — the fastest ELF linker.
| Feature | mold | lld | default (ld) |
|---|---|---|---|
| Symbol Resolution | Parallel (fine-grained mutex) | Sequential (global lock) | Sequential |
| Input File I/O | mmap (zero-copy) | mmap (zero-copy) | read() into heap |
| ICF | Multi-threaded (parallel hash+compare) | Sequential | Not available |
| Relocation | Parallel per-section | Parallel per-section | Sequential per-file |
| TLGP Relaxation | Built-in (GOT→PC-relative) | Partial | Partial |
| Build-ID | Fast mode (~zero cost) | SHA-1/MD5 | SHA-1 |
| Compact .dyn | Supported | Not available | Not available |
| Typical link time | 0.5-2s | 2-5s | 5-30s |
[linker]
preferred = "auto" # "auto", "mold", "lld", "default"
icf = "safe" # "none", "safe", "all"
relax = true # GOT→PC-relative conversion
threads = 0 # 0 = auto (75% of parallel jobs)
build_id = "fast" # "none", "fast", "sha1", "uuid"
compact_dyn = false
relro = true
bind_now = false1. Parallel Symbol Resolution — mold uses fine-grained mutex per hash bucket (not a single global lock like lld). This alone is 2-4x faster for large binaries.
2. ICF (Identical Code Folding) — runs in 3 parallel phases:
- Phase 1: Compute hash of each section (parallel)
- Phase 2: Group sections by hash (parallel)
- Phase 3: Compare candidates bit-by-bit (parallel)
- Result: 5-15% binary size reduction with zero runtime cost
3. TLGP Relaxation — converts GOT-indirect references to PC-relative:
; Before (indirect, 2 memory accesses):
mov rax, [GOT+foo]
; After (direct, 1 memory access):
lea rax, [rip+foo]4. Fast Build-ID — mold's "fast" mode generates build-IDs with near-zero cost (0x01 prefix + random bytes vs SHA-1 of entire output).
5. Compact .dyn — compresses the .dynsym section, reducing binary size for dynamic executables.
Beyond mold's built-in optimizations, rustm applies 6 additional algorithms:
| # | Algorithm | What It Does | Impact |
|---|---|---|---|
| 1 | Call Graph Clustering (hfsort+, cd-sort) | Reorders functions by call frequency | 5-15% runtime |
| 2 | Symbol Hash Strategy (Bloom prefilter, perfect hash) | Speeds up symbol lookup | 15-35% link time |
| 3 | Dead Code Elimination (aggressive, cross-module) | Removes unused code | 10-30% binary size |
| 4 | Section Ordering (TLB-aware, cache-line aligned) | Optimizes I-cache and TLB | 5-12% runtime |
| 5 | .eh_frame Dedup/Compression | Merges identical unwind entries | 5-15% binary size |
| 6 | GOT/PLT Full Optimization | Eliminates indirect calls, eager binding | 3-8% runtime |
Stacked maximum (cd-sort + hybrid hash + DCE + TLB + full GOT/PLT): 20-40% faster runtime + 15-30% smaller binary.
Applied automatically per profile:
- Dev profiles: Conservative (fast compile)
- Release profiles: Aggressive (maximum optimization)
fastest is the DEFAULT profile — maximum optimization stack:
| Profile | LTO | CGU | Opt | Strip | Panic | Incr | Backend | Flags | Use Case |
|---|---|---|---|---|---|---|---|---|---|
| fastest ⚡ | thin | 16 | 3 | yes | abort | no | LLVM | -C target-cpu=native |
DEFAULT — max optimization |
| dev-cranelift | none | 256 | 0 | no | — | yes | Cranelift | — | Ultra-fast dev iteration |
| dev-fast | none | 256 | 0 | no | — | yes | Auto | — | Fast dev iteration |
| dev-check | none | 256 | 0 | line-tables | — | yes | Auto | — | Fastest cargo check |
| balanced | thin | 16 | 2 | yes | — | yes | Auto | — | Good tradeoff |
| release-fast | thin | 16 | 3 | yes | abort | no | LLVM | -C target-cpu=native |
Fast release |
| release-max | fat | 1 | 3 | yes | abort | no | LLVM | -C target-cpu=native |
Maximum runtime perf |
| size-opt | thin | 1 | z | yes | abort | no | Auto | — | Minimal binary size |
rustm build --release --profile fastestSets these automatically:
CARGO_PROFILE_RELEASE_LTO=thin
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16
CARGO_PROFILE_RELEASE_OPT_LEVEL=3
CARGO_PROFILE_RELEASE_STRIP=symbols
CARGO_PROFILE_RELEASE_PANIC=abort
CARGO_PROFILE_RELEASE_INCREMENTAL=false
RUSTFLAGS=-C target-cpu=native -Wl,--icf=safe -Wl,--relax -Wl,--build-id=fast -Wl,-z,relro
rustm provides a complete PGO workflow — 10-30% runtime speedup:
# Step 1: Build instrumented binary
rustm build --release --profile release-fast --pgo-generate
# Step 2: Run your representative workload
./target/release/your-binary <benchmark-args>
# Step 3: Merge profile data
rustm pgo merge
# Step 4: Rebuild with profile data
rustm build --release --profile release-max --pgo-usePost-link optimization for 5-15% improvement on top of PGO:
# Collect perf profile
perf record -g ./target/release/your-binary <args>
# Convert for BOLT
perf2bolt -p perf.data -o bolt.fdata ./target/release/your-binary
# Apply BOLT
rustm bolt --binary ./target/release/your-binary --profile bolt.fdata --output ./optimized-binary# Auto-detect and enable CPU features (AVX2, FMA, AVX-512, NEON, SVE)
rustm build --release --target-featuresAutomatically enables:
- x86_64: +avx2, +fma, +sse4.2, +bmi1, +bmi2, +popcnt, +lzcnt, +avx512f, +avx512cd, +avx512bw, +avx512dq, +avx512vl
- aarch64: +neon, +sve, +sve2
Created by rustm init:
# rustm.toml
[build]
default_profile = "dev-fast" # Default profile name
codegen_backend = "auto" # "auto", "cranelift", "llvm"
incremental = true
strip = true
lto = "thin"
[cache]
sccache = true # Enable distributed cache
max_size_gb = 10
local_cache = true
[linker]
preferred = "auto" # "auto", "mold", "lld", "default"
icf = "safe" # "none", "safe", "all"
relax = true # GOT→PC-relative
threads = 0 # 0 = auto
build_id = "fast" # "none", "fast", "sha1", "uuid"
compact_dyn = false
relro = true
bind_now = false
[parallel]
jobs = 0 # 0 = auto-detect
[profiles.dev-fast]
lto = "none"
codegen_units = 256
opt_level = "0"
debug = "2"
incremental = true
[profiles.release-max]
lto = "fat"
codegen_units = 1
opt_level = "3"
strip = true
panic = "abort"
incremental = false
rustflags = ["-C", "target-cpu=native"]rustm <command> [options]
Commands:
build Build the project [aliases: b]
run Build and run the project [aliases: r]
check Check (fast, no binary) [aliases: c]
test Run tests with optimizations [aliases: t]
clippy Run clippy with optimizations [aliases: l]
clean Clean build artifacts and caches
config Manage configuration [aliases: cfg]
bench Build time benchmarks [aliases: bm]
profile Manage build profiles [aliases: pf]
doctor System optimization check [aliases: dr]
init Initialize config in project [aliases: i]
pgo PGO workflow [aliases: p]
llvm LLVM optimization info [aliases: ll]
bolt BOLT post-link optimization
Build options:
--release Build in release mode
--profile <NAME> Use a specific profile
--target <TRIPLE> Target triple
-f, --features <F> Cargo features
--all-features Enable all features
--no-default-features Disable default features
-j, --jobs <N> Number of parallel jobs
-v, --verbose Verbose output
-q, --quiet Quiet output
--codegen-backend <B> Codegen backend: auto, cranelift, llvm
--target-features Auto-detect CPU features (AVX2, NEON, etc.)
--pgo-generate Build instrumented binary for PGO
--pgo-use Rebuild with PGO profile data
--pgo-path <PATH> PGO profile path
--llvm-remarks Enable LLVM optimization remarks
$ rustm doctor🏥 rustm Doctor — System Optimization Check
💻 System Information
OS: linux | Arch: x86_64 | CPUs: 28
🔗 Linker Availability & Comparison
⚡ mold (v2.33.0) — BLAZING
🔥 lld (v18.1.0) — FAST
✅ Best available: mold (BLAZING)
⚡ Codegen Backend Availability
✅ Cranelift: available (rustup component)
✅ LLVM: always available (default backend)
→ Auto mode: Cranelift for dev, LLVM for release
📊 Codegen Backend Comparison
┌──────────────────────┬──────────────┬──────────────┐
│ Metric │ LLVM │ Cranelift │
├──────────────────────┼──────────────┼──────────────┤
│ Codegen speed │ Baseline │ 2-5x faster │
│ Memory usage │ Baseline │ 40-60% less │
│ Binary performance │ 100% │ 80-95% │
│ Optimization passes │ ~120 │ ~5 │
│ Auto-vectorization │ Full │ Limited │
│ LTO support │ Full │ None │
└──────────────────────┴──────────────┴──────────────┘
📌 Recommendations
1. Install sccache for distributed caching (30-70% faster incremental builds)
2. Install Cranelift for 2-5x faster dev builds: rustup component add rustc_codegen_cranelift --toolchain nightly
src/
├── main.rs # CLI entry point (clap)
├── core/
│ ├── mod.rs # Module re-exports
│ ├── config.rs # RustmConfig, BuildConfig, LinkerConfig (TOML)
│ ├── engine.rs # BuildEngine — orchestrates builds, env vars
│ ├── cache.rs # sccache integration
│ ├── linker.rs # LinkerInfo, LinkerSelector (mold/lld/default)
│ ├── linker_algo.rs # 6 advanced linker algorithms
│ ├── profile.rs # 8 built-in profiles (fastest is DEFAULT)
│ ├── parallel.rs # ParallelOptimizer (CPU × 1.5 × memory_factor)
│ ├── benchmark.rs # BuildTimer, BuildHistory (JSONL)
│ ├── llvm.rs # PGO, BOLT, AutoFDO, target-features
│ └── cranelift.rs # Cranelift codegen backend integration
├── commands/
│ ├── cli.rs # 15 commands (clap derive)
│ ├── build_cmd.rs # build, run, check, test, clippy
│ ├── clean_cmd.rs # Clean artifacts
│ ├── config_cmd.rs # Config management
│ ├── bench_cmd.rs # Build benchmarks
│ ├── profile_cmd.rs # Profile listing
│ ├── doctor_cmd.rs # System health check
│ ├── init_cmd.rs # Generate rustm.toml
│ ├── pgo_cmd.rs # PGO workflow
│ ├── llvm_cmd.rs # LLVM diagnostics
│ └── bolt_cmd.rs # BOLT optimization
└── utils/
├── format.rs # Output formatting
└── system.rs # System info helpers
┌─────────────────────────────────────────────────────────────┐
│ rustm Optimization Pipeline │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. CODEGEN BACKEND │
│ ┌──────────┐ dev builds │
│ │Cranelift │────2-5x faster codegen │
│ └──────────┘ │
│ ┌──────────┐ release builds │
│ │ LLVM │────maximum optimization │
│ └──────────┘ │
│ │
│ 2. CARGO PROFILE SETTINGS │
│ LTO=thin/fat, codegen-units, opt-level, strip, │
│ panic=abort, incremental=false │
│ (via CARGO_PROFILE_* env vars) │
│ │
│ 3. LINKER OPTIMIZATION (mold/lld) │
│ ┌──────────────────────────────────────────┐ │
│ │ mold: ICF=safe, relax, build-id=fast │ │
│ │ lld: fallback on Windows/macOS │ │
│ └──────────────────────────────────────────┘ │
│ │
│ 4. ADVANCED LINKER ALGORITHMS │
│ call-graph clustering, Bloom-filter symbol hash, │
│ aggressive DCE, TLB-aware section ordering, │
│ .eh_frame dedup, full GOT/PLT optimization │
│ │
│ 5. LLVM EXTRAS │
│ target-cpu=native, target-features=auto, │
│ PGO profile-generate/use, optimization remarks │
│ │
│ 6. POST-LINK (BOLT) │
│ Function/block reordering, I-cache optimization │
│ │
│ 7. CACHING │
│ sccache distributed compilation cache │
│ │
└─────────────────────────────────────────────────────────────┘
Expected optimization impact (compared to default cargo build --release):
| Optimization | Compile Time | Binary Size | Runtime |
|---|---|---|---|
Default cargo |
baseline | baseline | baseline |
| + mold linker | 5-10x faster link | same | same |
| + fastest profile | +20-50% | -10-20% | +10-15% |
| + Cranelift (dev) | 2-5x faster | — | -5-20% |
| + PGO | +50% | same | +10-30% |
| + BOLT | — | same | +5-15% |
| Stacked max | varies | -15-30% | +20-40% |
Contributions welcome! Areas of interest:
- Windows/macOS linker integration improvements
- New linker algorithms (e.g., ELF section compression)
- Cranelift backend detection on more platforms
- Benchmark data for different project sizes
- PGO automation workflows
- mold — Rui Ueyama's blazing-fast linker, the primary inspiration
- rustc_codegen_cranelift — Cranelift codegen backend for Rust
- sccache — Mozilla's distributed compilation cache
- BOLT — LLVM Binary Optimization and Layout Tool
- lld — LLVM's fast linker