What do the optimization levels `-Os` and `-Oz` do

2019-02-16 05:58发布

问题:

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.

回答1:

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.


回答2:

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.



标签: rust