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

cargo.toml: reduce release binary size by 10x #5

Merged
merged 1 commit into from
Dec 26, 2023

Conversation

waynr
Copy link
Contributor

@waynr waynr commented Dec 25, 2023

The new release profile options do the following:

  • strip = true causes debug symbols to be stripped from the final
    binary
  • codegen-units = 1 reduces redundancies in codegen optimizations by
    forcing all code generation through a single unit
  • lto = true something something link-time optimization

For me this took the binary size down from 7MB to roughly 682KB.

The new release profile options do the following:

* `strip = true` causes debug symbols to be stripped from the final
  binary
* `codegen-units = 1` reduces redundancies in codegen optimizations by
  forcing all code generation through a single unit
* `lto = true` something something link-time optimization

For me this took the binary size down from 7MB to roughly 682KB.
@garikello3d
Copy link
Owner

well, for some reason I thought the LTO is enable by default for Rust release build. Looks it is indeed enabled in some "thin" mode if not specified. But I agree that "fat" LTO is good to have, I don't care if my compile time jumps from 20 to 40 seconds.

regarding the stripping, I didn't enable it since it makes analysis of crashdumps impossible, as the stack trace will lack function names. I don't know how valuable to know in Rust ecosystem what is the stack trace my program crashed with.

@waynr what do you think?

@waynr
Copy link
Contributor Author

waynr commented Dec 25, 2023

@waynr what do you think?

I think it's reasonable to produce both a small binary (with debug symbols) for target environments that require it and a large binary (without debug symbols) for target environments that can tolerate tolerate it. These can both be built as part of an automated release pipeline; something I neglected to suggest in #4 was some kind PR pipeline for validating changes as they come in (eg run tests, validate different rust toolchain builds and platform targets) and an on-merge pipeline that handles all the necessary build and release activities.

@garikello3d garikello3d merged commit edc988a into garikello3d:main Dec 26, 2023
1 check passed
garikello3d pushed a commit that referenced this pull request Dec 26, 2023
The new release profile options do the following:

* `strip = true` causes debug symbols to be stripped from the final
  binary
* `codegen-units = 1` reduces redundancies in codegen optimizations by
  forcing all code generation through a single unit
* `lto = true` something something link-time optimization

For me this took the binary size down from 7MB to roughly 682KB.
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