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

Investigate lto & codegen units #785

Closed
Keats opened this issue Aug 24, 2019 · 6 comments
Closed

Investigate lto & codegen units #785

Keats opened this issue Aug 24, 2019 · 6 comments

Comments

@Keats
Copy link
Collaborator

Keats commented Aug 24, 2019

Right now the Cargo.toml has:

[profile.release]
lto = true
codegen-units = 1

in it for better performance at the cost of compilation speed.
Investigate how much additional time it takes & the perf difference.
This should be ideally done after #782

@southerntofu
Copy link
Contributor

I just tried commenting out these two lines from Cargo.toml and the results are interesting. A very naive benchmark on my side (simply renaming a variable in src/main.rs and building) shows:

  • the current config takes 2-3 minutes to rebuild and yields a 17Mb binary
  • commented-out lto/codegen-units takes 8-20 seconds to rebuild and yields a 22Mb binary

@samford
Copy link
Contributor

samford commented Sep 9, 2019

For what it's worth, looking back at the original post on the forum, this addition was proposed as a way of reducing binary size (rather than increasing performance), which still appears to hold true.

@Keats
Copy link
Collaborator Author

Keats commented Sep 9, 2019

Yep, I don't think many people are actually building the release version locally except for me. Maybe a better way would be to inject it only on CI? So users still get the small binary but don't suffer any penalties locally.

@samford
Copy link
Contributor

samford commented Sep 9, 2019

I had a similar thought, since it seems like the best of both worlds, but the concern with only having the release optimizations on CI is that it might lead to unoptimized binaries in other places.

For example, I remember that @ignatenkobrain maintains Zola on Fedora and it may be compiled from source in that context (rather than just downloading a binary from GitHub), so they would end up with an unoptimized release binary with the aforementioned setup. Anyone who maintains a separate build of Zola like this would have to know to add these optimizations to reduce the binary size (even if it was just uncommenting these lines in Cargo.toml).

I feel like it's better to have the release optimizations by default and anyone who needs faster release compilation locally can comment out the [profile.release] section in Cargo.toml.

@ignatenkobrain
Copy link
Contributor

Well, yes and no. We do pass codegen-units=1 in our RUSTFLAGS. But we don't have -C lto now. I am not sure why we haven't enabled it yet.

@Keats
Copy link
Collaborator Author

Keats commented Oct 10, 2019

Compelling argument @samford
Closing that.

@Keats Keats closed this as completed Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants