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 profile.release to enable link time optimizations #361

Open
rawhuul opened this issue Apr 26, 2024 · 2 comments
Open

Add profile.release to enable link time optimizations #361

rawhuul opened this issue Apr 26, 2024 · 2 comments
Labels

Comments

@rawhuul
Copy link

rawhuul commented Apr 26, 2024

Hi, the default profile.release for Cargo.toml is:

[profile.release]
opt-level = 3
debug = false
split-debuginfo = '...'  # Platform-specific.
strip = "none"
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false

It doesn't enable LTO which can be achieved easily by adding:

[profile.release]
opt-level = 3  <--- Can be changed to 's' for further binary size reduction
debug = false
lto = "fat"  <--- Enables LTO
strip = "debuginfo"
panic = 'unwind'
incremental = false
codegen-units = 1  <--- It impacts size of binary
rpath = false

As you can see in this screenshot, the first build binary has release size of 56mb and after applying opt-level='s', the binary size gets down to 32mb and the last build results in 36mb which performs LTO only

image

@tarkah
Copy link
Member

tarkah commented Apr 26, 2024

Hey @rawhuul thanks for the suggestion! I'd like to see us create a special profile specifically called packaging that can use these optimizations.

I use release profile a lot while developing and LTO will really kill compile times there, so I think we should only enable when "packaging" the app for release

@rawhuul
Copy link
Author

rawhuul commented Apr 26, 2024

Yup, you are right. This can be achieved easily, this feature is stable from rustc v1.57

[profile.packaging]
inherits = "release"
lto = “fat” 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants