build: fat LTO, code alignment and jemalloc for the release binary - #50
Merged
Conversation
The release profile shipped cargo defaults. On a Zen 5 host the big-body request path lost 6-7% throughput between two commits that execute the same instruction stream: op-cache misses tripled because the link layout moved serde_json's escaped-string loops onto worse fetch windows. Aligning functions to 64 bytes and branch targets to 32 bytes puts both layouts at the same op-cache miss rate. Fat LTO with one codegen unit is +13% on small bodies and -30% binary size; jemalloc is +16% on small bodies for either layout.
Collaborator
Author
|
Interleaved A/B on the Zen 5 bench host,
Per request over 300k big-body requests on the single lane: instructions 4,044,274 → 4,056,743 (+0.3%, LTO inlining), cycles 1,486,446 → 1,332,407 (−10.4%), IPC 2.72 → 3.05, op-cache misses 155,198 → 77,210, front-end no-op slots 4.94M → 3.51M. All responses 200. Linux binary 30.9 MB → 24.9 MB. |
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.
The release profile shipped cargo defaults. This sets
lto = "fat"andcodegen-units = 1, aligns functions to 64 bytes and branch targets to 32 bytes through.cargo/config.toml, and makesgwrun on jemalloc as its global allocator. One sentence indocs/deployment.md; no other code change.Why: on a Zen 5 host,
4e78c36lost 6-7% single-lane throughput on 48 KB bodies against5e94caawhile executing the same instruction stream to 0.01% — op-cache misses per request tripled (68k → 158k) because the link layout moved serde_json's escaped-string loops onto worse fetch windows; the malloc/realloc sequence, data-side counters and page faults were identical. With the alignment flags both layouts sit at 43k op-cache misses per request and within 0-3% of each other, no lane below its default. Fat LTO + one codegen unit measured +13% on small bodies and -31% binary; jemalloc (LD_PRELOAD control) +16% on small bodies for either layout while leaving the big-body layout gap untouched.Gates:
cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace,cargo deny checkclean on macOS and in arust:1.98.0Linux container; release build 129 s on the mac (was ~45 s), Linux binary 23.5 MB (was 30.9 MB). The interleaved A/B againstmain(single-big, pg40-big, single-small; instr/req, op-cache misses) follows in a comment.