Cinder

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.

keptrejectedleft of 0 is faster
P: the child work two times (the estimate)P/A 1.039 (1.029 to 1.049), 2 rounds+1.9 ms
A/A control of the P runA2/A 0.999 (0.990 to 1.008)-0.0 ms
Version 1: lazy children, a scan of the stored listB1/A 1.008 (1.003 to 1.013), 4 rounds+0.4 ms
A/A control of the version 1 runA2/A 1.003 (0.999 to 1.007)+0.1 ms
Version 2: lazy children, no scanB2/A 0.990 (0.982 to 0.998), 2 rounds-0.5 ms
A/A control of the version 2 runA2/A 0.995 (0.986 to 1.004)-0.2 ms
Version 2 against the control armB2/A2 0.995 (0.987 to 1.004)-0.2 ms
Change of the time per block against A, in ms, minimum over rounds, with the 95% bootstrap interval. Right of 0 is slower. The dot of P and of the two versions is the ms difference of the record. The other dots and all intervals are the ratio of the record minus 1, times the time of A in that run (49.4, 43.5 and 45.5 ms). All rows are grey: nothing was kept. 1 074 mainnet blocks, PGO and ThinLTO builds, one core of a desktop computer with other load, October 2026. Record: docs/results/2026-10-lazy-branch-decode.md.
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.

RowA: mainVersion 1Version 2
Work arena at the end of a block (mean of blocks)100 % of A87.3 % of A87.1 % of A
Work arena, largest block100 % of A91.9 % of A91.8 % of A
Peak RSS of a process of 12 blocks (mean of groups)100 % of A93.8 % of A94.9 % of A
Time per block (minimum over rounds)100 % of A100.8 % of A99 % of A
Each version as a percentage of A, bars from zero. Memory rows: the record values of the first round divided by A. Time row: the B/A ratio of the record. 1 074 mainnet blocks, October 2026. Record: docs/results/2026-10-lazy-branch-decode.md.
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.

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:

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

The internals pages describe the state root and the trie. To run Cinder on your own blocks, ask for access at getcinder.dev/access.