Skip to content

Instantly share code, notes, and snippets.

@jamesmishra
Last active June 1, 2025 17:48
Show Gist options
  • Save jamesmishra/f5d6cdfa4ef76db3daec17a82539af76 to your computer and use it in GitHub Desktop.
Save jamesmishra/f5d6cdfa4ef76db3daec17a82539af76 to your computer and use it in GitHub Desktop.
Rust Cargo optimization config
################################################################################
# 1. IDE / rust-analyzer: ultra-fast metadata only
################################################################################
################################################################################
# 1. Unit tests: slightly optimised deps so tests don’t timeout
################################################################################
[profile.test] # `cargo test`
opt-level = 1 # cheap “worth it” optimisations
debug = true
incremental = true
# Dependencies hot in tight loops run at -O3
[profile.test.package."*"]
opt-level = 3
debug = false
################################################################################
# 2. Interactive debugging run: optimise deps, lightly optimise your crate
################################################################################
[profile.dev] # `cargo run`
opt-level = 1 # your code keeps debug-friendly layout
debug = true
overflow-checks = true
incremental = true
codegen-units = 16
[profile.dev.package."*"] # all non-workspace crates
opt-level = 3 # full -O
debug = false
codegen-units = 1 # better inlining, only built once
incremental = false
# Speed up build-scripts / proc-macros that gate the build
[profile.dev.build-override]
opt-level = 3
################################################################################
# 3. Benchmarks / profiling: release-like speed *with* symbols
################################################################################
[profile.bench] # `cargo bench` or `cargo run --profile bench`
opt-level = 3
debug = true # keep DWARF for perf/flamegraph
codegen-units = 1
lto = "thin" # fast link, good inlining
incremental = false
panic = "abort"
################################################################################
# 4. Production release: smallest, fastest binary
################################################################################
[profile.release] # `cargo build --release`
opt-level = 3
codegen-units = 1
lto = "fat"
strip = "symbols"
panic = "abort"
overflow-checks = false
debug = false
[profile.check] # used automatically by `cargo check`
inherits = "dev" # keep debug defaults
opt-level = 0 # no code-gen optimisations
incremental = true # fine-grained reuse
codegen-units = 256 # maximum parallelism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment