What do the optimization levels `-Os` and `-Oz` do in rustc?

Lukas Kalbertodt picture Lukas Kalbertodt · Aug 10, 2017 · Viewed 7.4k times · Source

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.

Answer

Englund picture Englund · Aug 10, 2017

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.