22

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.

17

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.
  • I'm guessing "z" means strive for getting as close to "zero" size as possible? – Mehrdad Aug 10 '17 at 11:36
  • 4
    @Mehrdad I suppose it's more liks s is for Size, while z is for siZe. – Ruslan Aug 10 '17 at 14:28
  • 1
    Could you describe in more detail how s and z work compared to 0--3? Are they completely different optimization profiles? Or are they "like 2, plus a few additional optimization passes" or something like that? – Lukas Kalbertodt Aug 10 '17 at 15:47
11

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.

  • 1
    Could you describe in more detail how s and z work compared to 0--3? Are they completely different optimization profiles? Or are they "like 2, plus a few additional optimization passes" or something like that? – Lukas Kalbertodt Aug 11 '17 at 9:41
  • @LukasKalbertodt since those optimizations are performed by LLVM and are not rust-specific you should consult the LLVM documentation. – the8472 Dec 18 '17 at 9:43

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.