Executing rustc -C help
shows (among other things):
-C opt-level=val -- optimize with possible levels 0-3, s, or z
The levels 0 to 3 are fairly intuitive, I think: the higher the level, the more aggressive optimizations will be performed. However, I have no clue what the s
and z
options are doing and I couldn't find Rust-related information about them.
-O1 (optimize minimally) -O2 (optimize more) -O3 (optimize even more) -Ofast (optimize very aggressively to the point of breaking standard compliance)
6.4 Optimization levels. In order to control compilation-time and compiler memory usage, and the trade-offs between speed and space for the resulting executable, GCC provides a range of general optimization levels, numbered from 0--3, as well as individual options for specific types of optimization.
The degree to which the compiler will optimize the code it generates is controlled by the -O flag. No optimization. In the absence of any version of the -O flag, the compiler generates straightforward code with no instruction reordering or other attempt at performance improvement. -O or -O2.
It seems like you are not the only one confused, as described in a Rust issue. It seems to follow the same pattern as Clang:
Os
For optimising the size when compiling. Oz
For even more size optimisation.Looking at these and these lines in Rust's source code, I can say that s
means optimize for size, and z
means optimize for size some more.
All optimizations seem to be performed by the LLVM code-generation engine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With