All these tests are run on Lemmy tag v0.6.74, using cargo build --release
.
- Normal release build: 19mb
- After running
strip
13mb - Setting
opt-level=z
(optimize binary size): 21mb - Optimize for size +
strip
: 13mb - Optimize for size + enable link-time optimization: 14mb
- Optimize for size + lto +
strip
: 14mb - only lto: 15mb
- lto + strip: 11mb
- lto + strip + reduce codegen-units: 11mb
Check this document for a detailed explanation of these options
Based on these numbers and the difference in compile time between options (which I didnt record), lto + strip looks like the best option to me.
This is also useful: https://github.com/johnthagen/min-sized-rust
Cool, I’ll look later, but we have to make sure that smaller binary size doesn’t have a speed cost, I know some of those options do.
LTO should improve performance, as it allows for more optimizations, and dead code gets removed. Strip doesnt affect the behaviour at all. Only disadvantage is a longer compile time with LTO, but I think thats fine for releases.