| name | rust-release-profile |
| description | Configure release builds for maximum performance with LTO, optimizations, and binary stripping. Use for production deployments. |
Release Profile
Optimize Rust builds for production performance and binary size.
Production Cargo.toml Profile
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
strip = true
panic = 'abort'
[profile.release-with-debug]
inherits = "release"
debug = true
strip = false
Optimization Levels
opt-level = 3
opt-level = "s"
opt-level = "z"
Link-Time Optimization (LTO)
lto = true
lto = "thin"
lto = false
Codegen Units
codegen-units = 1
codegen-units = 16
Debug Symbols
strip = true
strip = "symbols"
strip = "debuginfo"
strip = "none"
[profile.release-perf]
inherits = "release"
debug = true
strip = false
Panic Behavior
panic = 'abort'
panic = 'unwind'
Target-Specific Optimization
[build]
rustflags = ["-C", "target-cpu=native"]
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-cpu=native"]
Profile for Different Use Cases
[profile.dev]
opt-level = 0
debug = true
[profile.release-quick]
inherits = "release"
lto = false
codegen-units = 16
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
strip = true
panic = 'abort'
[profile.release-perf]
inherits = "release"
debug = true
strip = false
[profile.release-small]
inherits = "release"
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = 'abort'
Workspace Settings
[profile.release]
opt-level = 3
lto = true
[profile.release.package.expensive-crate]
opt-level = 2
Build Commands
cargo build --release
cargo build --profile release-perf
ls -la target/release/my-binary
strip target/release/my-binary
file target/release/my-binary
Measuring Impact
time cargo build --release
time cargo build --release --config 'profile.release.lto=false'
cargo build --release
ls -la target/release/my-binary
cargo build --profile release-small
ls -la target/release-small/my-binary
hyperfine './target/release/my-binary' './target/release-quick/my-binary'
Guidelines
- Use
lto = true and codegen-units = 1 for production
- Use
strip = true and panic = 'abort' for smallest binaries
- Use
--profile release-perf with debug symbols for profiling
- Use
lto = "thin" for faster builds with good optimization
- Test different
opt-level values for your workload
- Use
target-cpu=native for deployment on known hardware
Examples
See hercules-local-algo/Cargo.toml for production profile.