Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider enabling more aggressive optimizations for the Dist profile: Fat LTO and codegen-units = 1 #15

Open
zamazan4ik opened this issue Jan 22, 2025 · 2 comments · May be fixed by #16
Labels
enhancement New feature or request

Comments

@zamazan4ik
Copy link

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.84, the latest version of this project at the moment, cargo build --profile dist command) - the results are below. I show only binary size changes since it's easier to measure them compared to performance differences in this app.

  • Current Dist profile: 4.2 Mib, clean build time: 6s
  • Dist + Fat LTO + codegen-units = 1: 2.9 Mib, clean build time: 16s

Thank you.

@solidiquis
Copy link
Owner

Thanks for the tip @zamazan4ik .. I'm in agreement that the more aggressive optimizations are warranted here. Would you like to submit a PR? If not I'll do it sometime this weekend which is also when I plan to do another release.

@zamazan4ik zamazan4ik linked a pull request Jan 22, 2025 that will close this issue
@zamazan4ik
Copy link
Author

Sure, here is the PR: #16

@solidiquis solidiquis added the enhancement New feature or request label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants