Description
Hi!
I see that the project already uses ThinLTO in the Dist profile in the root Cargo.toml
file. However, ThinLTO is usually less efficient from the perspective of performed optimizations than Fat (aka Full) LTO, and cargo-dist
defaults are not the most optimal by default. Additionally, I suggest enabling codegen-units = 1
(CG1) too. Enabling more advanced optimizations allows us to reduce the binary size further (always a good thing) and improve the application performance more.
Basically, it can be enabled with the following change:
[profile.dist]
inherits = "release"
codegen-units = 1
lto = true
I have made quick local tests (AMD Ryzen 5900x, Fedora 41, Rust 1.85.1, the latest version of this project at the moment, cargo build --profile dist
command) - the results are below.
- ThinLTO (current Dist profile): 9.5 Mib, clean build time: 22s
- ThinLTO +
codegen-units = 1
: 7.4 Mib, clean build time: 38s - FatLTO: 7.3 Mib, clean build time: 46s
- FatLTO +
codegen-units = 1
: 6.8 Mib, clean build time: 57s
I didn't perform performance benchmarks but FatLTO + CG1 should be the most optimized version too.
Thank you.