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

Add build profile optimized for binary size #1765

Closed
wants to merge 1 commit into from

Conversation

apiraino
Copy link
Contributor

This patch adds a new build profile optimized for binary size.

If we exclude the triagebot application, when building the other binaries under ./src/bin I think it can make sense to optimize for binary size rathen than performance. When taken to the extreme (as in this patch), the differenze is just huge, see the following table (rust nightly 1.77):

$ la -h target/{release,opt-size}/{compiler,types,lang,prioritization-agenda}
-rwxr-xr-x 2 me me 4.0M Jan 24 17:13 target/opt-size/compiler
-rwxr-xr-x 2 me me 4.1M Jan 24 17:13 target/opt-size/lang
-rwxr-xr-x 2 me me 4.1M Jan 24 17:13 target/opt-size/prioritization-agenda
-rwxr-xr-x 2 me me 4.0M Jan 24 17:13 target/opt-size/types
-rwxr-xr-x 2 me me 140M Jan 24 17:21 target/release/compiler
-rwxr-xr-x 2 me me 141M Jan 24 17:21 target/release/lang
-rwxr-xr-x 2 me me 141M Jan 24 17:21 target/release/prioritization-agenda
-rwxr-xr-x 2 me me 140M Jan 24 17:21 target/release/types

I like to run the build of these ancillary tools with cargo build --bins --profile=opt-size.

Opinions?

Thanks for a review.

Cargo.toml Show resolved Hide resolved
@@ -56,3 +56,12 @@ default-features = false

[profile.release]
debug = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we tweak this to = 1 which should be enough for good backtraces and see if that solves most of the size problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a bit bigger (~61 mb) than using the profile in this patch (~4 mb).

$ la -h target/{release,debug1}/{compiler,types,lang,prioritization-agenda}
-rwxr-xr-x 2 me me  61M Jan 25 11:39 target/debug1/compiler
-rwxr-xr-x 2 me me  62M Jan 25 11:39 target/debug1/lang
-rwxr-xr-x 2 me me  62M Jan 25 11:39 target/debug1/prioritization-agenda
-rwxr-xr-x 2 me me  61M Jan 25 11:39 target/debug1/types
-rwxr-xr-x 2 me me 140M Jan 25 11:36 target/release/compiler
-rwxr-xr-x 2 me me 141M Jan 25 11:36 target/release/lang
-rwxr-xr-x 2 me me 141M Jan 25 11:36 target/release/prioritization-agenda
-rwxr-xr-x 2 me me 140M Jan 25 11:36 target/release/types

The second biggest "contributor" in the profile in this patch is strip = true that brings the size from ~61mb down to ~6mb so probably:

[profile.release]
debug = 1
strip = true

would bring home most of the benefits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway: no problem, I'll just keep this patch in a stash for personal use.

Thanks for your time.

@apiraino apiraino closed this Jan 25, 2024
@apiraino apiraino deleted the opt-size-build-profile branch January 25, 2024 10:51
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

Successfully merging this pull request may close these issues.

2 participants