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

Reduce release binary size #36

Merged
merged 1 commit into from
Jan 12, 2025

Conversation

davfsa
Copy link
Contributor

@davfsa davfsa commented Jan 11, 2025

strip = true alone reduces the size by 40MB!

I have unfortunately not been able to measure the effect of the other settings, but in my experience they reduce the size drastically on projects that have a lot of dependencies (like this one).

LTO (Link-Time optimizations): This should help out trim code from dependencies that is not used, that can be detected at link time, which I believe there is a lot of. Note: Depending on the project, this might add a substantial amount of time to the release builds, but I have not been able to test it at the time of writing. Any help to get that working to measure the time vs size gains is welcome :)
Optimize for size: As the option implies, it will optimize the binary for size rather than for speed. It is the equivalent of -02 with some more precautions to make the binary smaller. In rustc 1.18.0+, using opt-level = s is a combination of LLVM flags, setting speed optimization to 2 (ending in the same optimizations as opt-level = 2) and size optimization to 1 (2 being aggressive). I generally prefer this than 'z' as it can actually degrade performance.

Further paths to reduce the size of the binary would be to trim down those dependencies and cleanup the code with a tool like cargo-bloat.

Relates to #6

`strip = true` alone reduces the size by 40MB!
@Exidex Exidex force-pushed the task/reduce-release-size branch from cc3d327 to d357a91 Compare January 11, 2025 19:14
@Exidex
Copy link
Member

Exidex commented Jan 11, 2025

I was surprised to see the binary size to be that big when I did first releases. I guess this is the result of using biggest opensource rust project as dependency (which is Deno). But I have been prioritizing other things, so thanks so much for taking a look at this.

I compared builds on main and this PR, and on my machine linking does indeed almost triple build time, on github actions it doesn't seem to be quite as bad. But to be honest I don't really mind increase build time if it is only for release mode.

But binary size reduction is incredible, 185MB -> 103MB on Linux

Do you think this is ready for merging, or is there anything else to be done?

@davfsa
Copy link
Contributor Author

davfsa commented Jan 12, 2025

I compared builds on main and this PR, and on my machine linking does indeed almost triple build time

That's what I would expect, it's really unfortunately that's the case 😔

But binary size reduction is incredible, 185MB -> 103MB on Linux

Really glad to hear! Should also boost performance a bit (LTO does that!)

Do you think this is ready for merging, or is there anything else to be done?

I believe it's good if you are happy with the changes :)

@Exidex Exidex merged commit e7c8575 into project-gauntlet:main Jan 12, 2025
3 checks passed
@Exidex
Copy link
Member

Exidex commented Jan 12, 2025

Thank you!

@Exidex Exidex added the type: fix PR that is fixing a bug label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: fix PR that is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants