Fine-tuning performance vs. executable size optimizations

261 Views Asked by At

I have a Rust program whose executable size I'd like to decrease by 15-20% compared to its opt-level = 3 size. What makes me hopeful is that compiling with opt-level = "s", i.e. asking Rust to optimize for size, I get a 45% size decrease compared to the performance-optimized version:

Optimization level Code size (.text + .data segments)
3 27,380 bytes
2 23,934 bytes
1 27,852 bytes
s 15,132 bytes
z 15,264 bytes, but miscompiled (must be some LLVM AVR backend bug, wouldn't be the first...)

However, the runtime performance of the s-optimized version doesn't meet my performance requirements (it's a game for a fixed hardware platform, so there's a performance requirement coming from the frame rate).

Before I start putting in "real work" to decrease code size and/or improve performance by writing "better" code, I'd like to explore what the compiler can do for me. Initially I thought I can just try tuning the inline-threshold setting, but based on the comments on that question, there's (a lot) more going on between Rust's "s" vs 3 optimization levels.

So my question is, what are the various parameters/axes/degrees of freedom of the Rust compiler than I can fine-tune in the hope of getting acceptable performance and smaller code size?

0

There are 0 best solutions below