perf(programs): build the ethrex guest with thin LTO - #861
Merged
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: e36794d · Baseline: cached · Runner: self-hosted bench |
Collaborator
|
/bench |
diegokingston
approved these changes
Jul 24, 2026
Collaborator
|
/bench |
Collaborator
|
/bench |
jotabulacios
approved these changes
Jul 31, 2026
MauroToscano
added a commit
that referenced
this pull request
Jul 31, 2026
The branch predated #861 (thin LTO on the ethrex guest) and #863, so every cycle count and derived cost in these docs described a guest that no longer exists. Re-measured on this branch at the merge, guest rebuilt from source: real block 74,819,518 -> 50,781,557 cycles synthetic 9,063,727 -> 8,734,622 cycles ratio ~7x -> ~5.8x so the CPU prove drops ~6 min -> ~4.5-4.8 min and the monolithic-heap figure ~330 GB -> ~240 GB (re-derived from the same measured growth fit via a same-ELF cycle ratio, not rescaled by hand). Accelerator call counts are unchanged at 10,478 keccak / 116 ECSM, as expected — they follow the workload, not codegen. Every count now names the ELF it came from. Two things move them and both have bitten this doc already: guest optimisation (#861), and the clang major on PATH, worth ~2% — the Makefile pins the guest's target flags but not its compiler, so `cc` takes whatever clang is installed. The 50,713,534 the RTX 5090 box measured for this block on the same main commit is that effect, not a regression: clang 18 there, clang 21 here, 0.13% apart. GPU is no longer unmeasured: 59.87 s wall at --epoch-size-log2 22 on an RTX 5090, which is the recommended GPU epoch because VRAM binds — 2^22 leaves 28.9% headroom and 2^23 does not fit a 32 GiB card at all. CPU is ~4.5-4.8x that wall time. The CPU-server epoch recommendation is left as "pending calibration" rather than guessed from the GPU figure. The two alternate candidate blocks keep their PRE-LTO numbers, explicitly labelled and marked for re-measurement. Removing them would lose the selection evidence; presenting them next to a main-vintage number without a label would be exactly the vintage-mixing error the rest of this change is about.
This was referenced Jul 31, 2026
Merged
Merged
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.