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