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 9 5900x, Fedora 42, Rust 1.86, the latest version of this project at the moment, cargo build --profile dist
command) - the results are below.
- ThinLTO (current Dist profile): 82 Mib, clean build time: 2m 15s
- FatLTO +
codegen-units = 1
: 65 Mib, clean build time: 4m 42s
Since the Dist profile is used only for release binaries, this build time increase shouldn't be a problem for the project.
Thank you.