An estimate of 3.9% and a result in the noise: why we rejected lazy branch decode
TL;DR
After the compact hash references of #272, a decoded trie branch still makes a small reference node for each child that is a hash. A walk goes to one or two of the 16 children. So we tried to make a child node only when a walk reaches it. Our rule is to measure the possible gain before we build. A scratch build that did the child work two times gave B/A 1.039 (95% interval 1.029 to 1.049): about 3.9% of the block time. We built two versions and ran them on 1 074 mainnet blocks, with an A/A control in the same interleaved runs. Version 1 was slower: 1.008 (1.003 to 1.013). Version 2 gave 0.990 (0.982 to 0.998) against A. Against the A/A control arm it gave 0.995 (0.987 to 1.004), and the A/A control itself gave 0.983 by the mean over rounds. The work arena of a block was 13% smaller in both versions. The block time did not follow. The estimate was too high. The scratch build added 5.1 MB of new memory per block, and that new memory was the cost it measured. We rejected the change on 2026-10-24. The code stays on a branch.
Some changes do not make it. This post is about one of them, and about the numbers that stopped it. I like this kind of story. The plan was sound, we measured the estimate and did not guess it, and the result was still nothing. The interesting part is why.
The idea: do not make children that nobody visits
A branch node of the Merkle Patricia trie has up to 16 children. In the encoded node, most children are only the keccak-256 hash of the child. When Cinder decodes a branch, it makes an object for each child. Since the compact hash references of #272, a child that is only a hash gets a small reference node of 40 bytes in the arena, not a full node of 208 bytes. That change made a block take 0.923 of the time of the base, and the work arena 37% smaller.
But a walk through the trie goes to one or two of the 16 children. The code makes the other references, keeps them until the end of the block, and never reads them. So the next idea was clear: make a child node only when a walk reaches it. Until then, the child stays a 32-byte hash inside the encoded branch, which we already have in memory.
First, the possible gain
We have a rule: measure the possible gain before you build. Our bar is 1% of the block time. A smaller gain is not worth the risk in trie code, where one wrong byte changes a state root.
To find the cost of the child nodes, we made a scratch build, P, that we did not commit. For each decoded branch, P made the 16 child references, did not keep them, and then made them again. The extra time of P is then the cost of that work one time.
P added 1.9 ms per block: 3.9% of the block time. By the minimum over rounds, P/A was 1.039 (95% interval 1.029 to 1.049). The A/A control of the same run gave 0.999. By the mean over rounds, P/A was even larger: 1.061 (3.43 ms). That is well clear of the noise, and well above our bar. So we built the change.
Two versions, measured the same way as #272
Version 1 did not make the child nodes at all. When a walk needed a child, it read the stored branch with the RLP decoder up to that child. When the encoder wrote a changed branch, it read all 16 items again.
Version 2 was lazy only when each child is empty or a hash reference. Then each item is 1 or 33 bytes, and the position of item i is a short byte count, with no decoder.
Both versions still check all 17 items when they decode a branch, so a corrupt or short branch is an error at the first walk, not later.
The result: one slower, one in the noise
Version 1 was slower. Version 2 was inside the band of the A/A control. No version came near the estimate.
| Run, minimum over rounds | Rounds | Ratio | 95% interval | A/A control of the same run |
|---|---|---|---|---|
| P: the estimate | 2 | P/A 1.039 (+1.92 ms) | 1.029 to 1.049 | 0.999 (0.990 to 1.008) |
| Version 1 | 4 | B1/A 1.008 (+0.36 ms) | 1.003 to 1.013 | 1.003 (0.999 to 1.007) |
| Version 2 | 2 | B2/A 0.990 (-0.45 ms) | 0.982 to 0.998 | 0.995 (0.986 to 1.004) |
| Version 2 against the control arm | 2 | B2/A2 0.995 | 0.987 to 1.004 |
A block of A took 49.4 ms in the P run, 43.5 ms in the version 1 run and 45.5 ms in the version 2 run (minimum over rounds, mean of the blocks). The same binary, on the same blocks, moved by several milliseconds between runs. That is why each run has its own A and its own A/A control, and why we compare ratios inside one run.
Version 2 needs a second look, because 0.990 with an interval that ends at 0.998 can look like a small win. It is not one we can claim. A2 is the same binary as A, and in the same run it came out at 0.995 against A. Against A2, version 2 is 0.995, and that interval includes 1. By the mean over rounds, the A/A control itself gave 0.983. When a binary can differ from its own copy by that much, a change of that size says nothing. We stopped the version 2 run after 2 rounds for that reason.
Memory went down, the time did not
The work arena of a block was 13% smaller in both versions. The block time did not move by more than the noise.
| Row | A: main | Version 1 | Version 2 |
|---|---|---|---|
| Work arena at the end of a block (mean of blocks) | 100 % of A | 87.3 % of A | 87.1 % of A |
| Work arena, largest block | 100 % of A | 91.9 % of A | 91.8 % of A |
| Peak RSS of a process of 12 blocks (mean of groups) | 100 % of A | 93.8 % of A | 94.9 % of A |
| Time per block (minimum over rounds) | 100 % of A | 100.8 % of A | 99 % of A |
| Memory, first round | A | Version 1 | Version 2 | P |
|---|---|---|---|---|
| work arena at the end of a block, mean of blocks | 36.3 MB | 31.7 MB | 31.6 MB | 41.4 MB |
| work arena at the end of a block, largest block | 73.2 MB | 67.3 MB | 67.2 MB | 85.0 MB |
| peak RSS of a process of 12 blocks, mean of groups | 132.6 MiB | 124.4 MiB | 125.9 MiB | 142.3 MiB |
So the change did what it said. It made fewer objects and used less memory. It just did not make a block faster. Less memory is good, but it is not the reason we work on the trie. A node that has memory to spare gets little from a smaller arena, and the change adds a new path through the code that every walk, proof and encoder must get right.
Why the estimate was too high
This is the part I find the most useful.
- Version 1 paid more than it saved. Its arena was 4.6 MB smaller per block. But each child that a walk made needed a scan of the stored list with the RLP decoder, and each changed branch needed a read of all 16 items again. That cost more than the nodes it did not make.
- Version 2 removed the scan, and the time still did not move. Its arena was 4.7 MB smaller, and the branch node stayed at 208 bytes. The time change stayed in the noise.
- The estimate measured a different cost. In P, the second set of child nodes added 5.1 MB of new memory per block, after the first set. New memory is slow memory: it is not in the cache yet. In the base, the code writes each child node into memory that the decode touches at that time, while that data is still in the cache. That costs little. So P measured “16 nodes in cold memory”, and the real code pays for “16 nodes in warm memory”.
- A lazy child is not free either. The walk must make it later, and the encoder must read its hash from the stored list.
The arena chart above shows the trap. P was the only build with 41.4 MB of arena by the mean, against 36.3 MB for A. The estimate came with its own extra memory, and that extra memory was the cost it measured.
What we take from it
About estimates. “Do the work two times” is a good method for work that computes. For work that only makes small objects, it gives too large a value, because the second copy lands in new memory. For this type of work, the record now names two better methods: a scratch build that does not do the work at all (when the results still let the block run to the end), or a count of the objects multiplied by their measured cost. The estimate was not a waste. It was a measurement, and it told us to build. It also gave us a number to check the result against. Without it, a B/A of 0.990 could look like a small win. With it, we expected about 1.9 ms, saw less than half a millisecond, and asked why.
About the decision. We did not keep version 2 for its memory, and we did not keep it as “maybe 1% faster”. The A/A control is in the same runs for this reason: a ratio means little until you see how far a copy of A moves. Here, the copy of A moved as far as the change did.
What we keep:
- The record, with all three runs, the memory table and the method.
- The code, on a branch, not merged.
- The two new tests on that branch. One checks that one read makes 1 KiB or less of nodes, and that the root and the proofs are the same as on a trie built in memory. The other gives corrupt branches to the decoder: references of the wrong length, the wrong number of items, a list cut short, and an embedded item that is not a node.
Both versions gave the same result as mainnet on every block with a complete witness (8 blocks have an incomplete witness, as with the base), and the unit tests passed with the sanitizers. We did not run the database test suites, because we had already decided to reject the change.
What this does not show
- That lazy decode can never help. It shows that these two versions did not help on these blocks, on a desktop, under load, with the compact references already in place. Before #272, each child was a full node of 208 bytes, and the result could have been different. We did not measure that.
- A live node. This is a replay of fixture blocks, not a measurement next to reth on the measurement server.
- The reason in hardware counters. The cache explanation fits all the numbers in the record. We did not measure cache misses to prove it.
The internals pages describe the state root and the trie. To run Cinder on your own blocks, ask for access at getcinder.dev/access.