Repository navigation
build: shrink the release binary with fat LTO and one codegen unit - #55
Merged
Merged
Conversation
Cargo.toml had no [profile.release], so release builds used 16 codegen units and no cross-crate LTO (release.yml's comment claiming LTO was on by default was wrong). rustc gives each codegen unit its own copy of every closure and async body it uses, which left about a fifth of .text as duplicates: `main`'s async body alone appeared three times. Stripped macOS arm64 binary: 13458360 -> 9181064 bytes (-32%), .text 9353156 -> 6844104. Threaded wasm: 4911967 -> 4153657 bytes (it gets the single codegen unit but no LTO, since cargo can't LTO a cdylib+rlib lib). Panics stay `unwind`. `abort` would save another ~2 MiB, but it would turn a panic in one peer session's task into the end of the whole process. release.yml now builds only `--bin hoverfly`, so the unshipped sigcheck doesn't cost a second fat-LTO link.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cargo.tomlhad no[profile.release], so release builds used the defaults: 16 codegen units and no cross-crate LTO. The comment inrelease.ymlsaying LTO was on by default was wrong.rustc gives each codegen unit its own copy of every closure and async body that unit uses. That left about a fifth of
.textas duplicates:main(about 138 KB) appeared three times;bridge::run_leg,client::push_chunks_with_pool_innerandresolve_feed_rootappeared 3–4 times each.Fat LTO with a single codegen unit merges these copies.
Results
Measured on macOS arm64 with stripped binaries, the same form the release tarballs ship.
.textgzip -9All figures are bytes.
cdylibandrlib.hoverfly bmton a random 50 MB file gives the same roots with both binaries and takes the same time (about 0.27 s).Why panics stay
unwindpanic = "abort"would save another 2083856 bytes (7097208 total). But each peer session runs its libp2p swarm in its own tokio task (spawn_session_driver). Withunwind, a panic in that task, for example a dependency choking on a peer's bytes, drops only that session. Withabortit would end the whole upload, daemon or relay.AGENTS.mdnow records this so nobody switches it later.Errors (
Results, such as libp2p dial failures or resets) aren't affected either way. The setting only changes what happens on a panic.Other changes
release.ymlnow builds only--bin hoverfly.sigcheckisn't shipped, so this avoids paying for a second fat-LTO link.Notes
release.yml, the bench workflows, CircleCI and theDockerfile. Debug builds (cargo build) are unchanged.