perf(l1): keep the memoize_hashes guard out of the recursive call #7101
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.46) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 271 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.335
Real PR Conversation Timeline
1 comments
"Review active on #7101"
general
weight: 0.35
ElFantasma
Motivation
NodeRef::memoize_hashesalready skips subtries whose hash is memoized, andNodeRef::Hashreferences have nothing to memoize at all. The problem is where that check lives:Node::memoize_hashesvisits all 16 children of a branch node, and because the body is recursive LLVM will not inline it — so every child costs a real function call even when the answer is immediately "nothing to do".How lopsided that is, measured on a real mainnet block execution witness (block 25368371):
| child references | count | share |
|---|---|---|
|
NodeRef::Node(embedded, must be hashed) | 1,273 | 7.3% ||
NodeRef::Hash(hash only, nothing to do) | 13,102 | 75.1% || empty slots | 3,086 | 17.6% |
So ~93% of the references a branch iterates over have no work behind them. Counting actual calls during a stateless execution of that block:
Description
Split the guard into an
#[inline]shell and move the recursive body into a separate function, so the overwhelmingly common no-op case becomes a load and a branch at the call site instead of a call.Behaviour is unchanged — this is purely about where the code lives.
cargo test -p ethrex-triepasses (61 tests),fmtandclippyare clean.Effect
The win scales with how poorly the call overhead is amortised. The measurement above comes from the LambdaVM zkVM guest, where every executed RISC-V instruction is proven and there is no out-of-order core to hide the call:
| | cycles |
|---|---|
| before | 26,794,880 |
| after | 25,314,781 |
| | −1,480,099 (−5.52% of total block execution) |
memoize_hashesdisappeared from the guest profile entirely (1,786,030 → 0 self cycles), and the trie went from 20.5% to 15.9% of the block.Native gains will be considerably smaller — a modern core predicts and pipelines these calls well — but the change strictly removes work, so it should not regress anywhere. Happy to add a native benchmark if you'd like a number for that path before merging.