Rust applies optimizations based on the `opt-level` setting in your `Cargo.toml` profile, with level 0 for development and level 3 for release builds.
Rust applies compiler optimizations based on the build profile defined in Cargo.toml, ranging from no optimization in dev to aggressive optimization in release. You control the intensity of these optimizations by setting the opt-level configuration, where 0 disables them for faster compilation and 3 enables the maximum level for faster execution.
[profile.dev]
opt-level = 0
[profile.release]
opt-level = 3
Rust automatically makes your code run faster or compile faster depending on whether you are testing or shipping it. Think of it like a car engine that runs quietly and efficiently when you are just warming it up, but shifts into high gear when you are ready to drive on the highway. You tell the compiler which mode to use by changing a setting in your project file.