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
So optimizing for size increases binary size?
In our case yes. Quote from the docs I linked above: