perf(programs): build the ethrex guest with thin LTO#861
Open
MauroToscano wants to merge 1 commit into
Open
Conversation
The ethrex guest crate had no [profile.release], so it built with cargo's release defaults (lto = false, codegen-units = 16). Adding thin LTO lowers the number of instructions the VM executes for a real ethrex block, at no runtime cost — execution is priced per executed instruction, so the small ELF-size increase (3.64 MB -> 3.82 MB) is free. Measured on the committed fixtures (same toolchain, same inputs): ethrex_bench_4.bin: 3,841,262 -> 3,750,291 cycles (-90,971, -2.37%) ethrex_bench_16.bin: 11,616,950 -> 11,352,127 cycles (-264,823, -2.28%) Syscall invariants are identical before and after (Keccak 174 / Ecsm 16 for _4, Keccak 356 / Ecsm 64 for _16): the guest does exactly the same work, LTO just compiles it into fewer executed instructions.
Contributor
Author
|
/bench |
Benchmark — ethrex 20 transfers (median of 3)Table parallelism: auto (cores / 3)
Commit: 9461f88 · Baseline: cached · Runner: self-hosted bench |
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.
What
Add a
[profile.release]withlto = "thin"to the ethrex guest crate(
executor/programs/rust/ethrex/Cargo.toml). The crate previously had no[profile.release]at all, so it built with cargo's release defaults(
lto = false,codegen-units = 16).Why
Thin LTO measurably lowers the number of instructions the VM executes for a
real ethrex block, at no runtime cost — execution in this VM is priced per
executed instruction, so the small ELF-size increase is free.
Measured on the committed fixtures (same toolchain, same inputs):
ethrex_bench_4.binethrex_bench_16.binThe syscall invariants are identical before and after (Keccak 174 / Ecsm 16 for
_4, Keccak 356 / Ecsm 64 for_16) — the guest does exactly the same work;LTO just compiles it into fewer executed instructions.
Methodology
Deterministic A/B on a dedicated 32-core rig, same toolchain
(
nightly-2026-02-01,-Z build-std,riscv64im-lambda-vm-elf), cycles readvia
cli execute --cycleson the committed fixtures. The measurement noisefloor is exactly 0: the pristine baseline was built twice in separate
CARGO_TARGET_DIRs and produced byte-identical ELFs, so the deltas above arethe whole signal.
Size
Guest ELF grows 3.64 MB → 3.82 MB (+4.9%). This is free here: the VM charges
per executed instruction, not by ELF size.
Follow-up (out of scope)
A tuned variant — thin LTO plus
-C llvm-args=-inline-threshold=2500/-unroll-threshold=2000— measured a further ~2× improvement(
ethrex_bench_1611,035,843, −5.00% total;ethrex_bench_43,616,998,−5.84% total) at +66% ELF size. That inline/unroll tuning is deliberately left
out of this PR and can land as a separate change.