15

The rustc compiler has four optimization levels, just like GCC:

opt-level
This flag controls the optimization level.

0: no optimization, also turns on cfg(debug_assertions) (the default).
1: basic optimizations.
2: some optimizations.
3: all optimizations.
s: optimize for binary size.
z: optimize for binary size, but also turn off loop vectorization.

If I make a build with Cargo and its --release option, which optimization level is used?

cargo build --release
Finished release [optimized] target(s) in 0.75s
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Bence László
  • 494
  • 2
  • 5
  • 14

1 Answers1

25

According to the cargo manual, the default level for release builds is -O3.

# The release profile, used for `cargo build --release` (and the dependencies
# for `cargo test --release`,  including the local library or binary).

[profile.release]
opt-level = 3
debug = false
split-debuginfo = '...'  # Platform-specific.
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false
apetranzilla
  • 5,331
  • 27
  • 34