Build Time Optimization Guide â
This document outlines the build optimizations applied to the yumlabs project.
Optimizations Applied â
1. Cargo Build Profiles (Cargo.toml) â
Development Profile (dev) â
opt-level = 0: No optimization for fastest compilationcodegen-units = 256: Maximum parallelization during compilationincremental = true: Incremental compilation enabled (default, but explicit)- Dependency optimization: All dependencies compiled with
-O2even in dev mode- Dependencies are compiled once but used many times, so optimizing them improves runtime without affecting incremental build times
Release Profile (release) â
opt-level = 3: Maximum optimization for best performancelto = "thin": Thin Link-Time Optimization for better optimization with reasonable compile timecodegen-units = 1: Single codegen unit for maximum optimizationstrip = true: Strip debug symbols for smaller binary sizepanic = "abort": Smaller binary and faster panic handling
Fast Release Profile (release-fast) â
- New custom profile for quick release testing
opt-level = 2: Good optimization without the full cost of-O3lto = false: No LTO for faster linkingcodegen-units = 16: Parallel compilation for faster builds- Use with:
cargo build --profile release-fast
2. Linker Optimization (.cargo/config.toml) â
rust-lld.exe: Uses LLVM's LLD linker instead of MSVC's default linker- 2-5x faster linking on Windows
- Comes bundled with Rust, no additional installation needed
3. Build Settings â
jobs = 0: Uses all available CPU cores for parallel compilationprotocol = "sparse": Faster crate index updates (requires Rust 1.68+)git-fetch-with-cli = true: Better git performance for dependencies
Expected Performance Improvements â
| Build Type | Expected Improvement |
|---|---|
| Initial clean build | 10-30% faster |
| Incremental builds | 30-50% faster |
| Dependency updates | Significantly faster |
| Linking time | 2-5x faster |
Usage â
Development Builds â
bash
cargo build # Uses optimized dev profile
cargo run # Fast compilation with optimized dependenciesRelease Builds â
bash
cargo build --release # Full optimization (slower build, fastest runtime)
cargo build --profile release-fast # Quick release build for testingAdditional Tips â
- Clean builds when needed: If you encounter issues, run
cargo cleanand rebuild - Dependency caching: First build will be slower as dependencies are optimized, subsequent builds will be much faster
- Parallel compilation: Ensure you have sufficient RAM (256 codegen units can be memory-intensive)
- Monitor build times: Use
cargo build --timingsto analyze build performance
Troubleshooting â
If builds are slower â
- Reduce
codegen-unitsin dev profile (try 128 or 64 instead of 256) - Ensure you have enough RAM for parallel compilation
If linker fails â
- Remove the linker configuration from
.cargo/config.toml - Fall back to default MSVC linker
If you need debug symbols in release â
- Set
debug = truein[profile.release] - Or use
cargo build --profile release-fastwhich can be modified to include debug info
Files Modified â
Cargo.toml: Added build profiles.cargo/config.toml: Added linker and build configuration (created new)