Skip to content

merkle: copy walker pages on freeze, and freeze them in parallel - #989

Draft
citizen-stig wants to merge 3 commits into
thrumdev:masterfrom
citizen-stig:nikolai/cow-walker-pages
Draft

citizen-stig wants to merge 3 commits into
thrumdev:masterfrom
citizen-stig:nikolai/cow-walker-pages

Conversation

@citizen-stig

@citizen-stig citizen-stig commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Walker stack pages become CowPage: either a fresh page, or a shared cache page plus the nodes changed on top of it. The 4 KiB copy of a shared page moves out of the page walker (Session::finish) to the point where updated pages are frozen (into_overlay / commit).
  • The walker's reconstruction mode keeps copying eagerly. Only tests use it, and they compare whole reconstructed pages.
  • UpdatedPages::into_frozen_iter freezes the per-worker page lists in parallel, so the copies that moved into into_overlay / commit are not done serially.

Why

Most pages the walker touches change only a few nodes. Copying each page on first touch puts about 85k 4 KiB copies on the finish critical path.

The copy moves out of finish; it doesn't disappear. Read the benchmarks with finish and into_overlay together.

Notes

Benchmarks

finish_bench on all 16 CPUs (8 cores) against master 6ee36d3, at commit_concurrency 8 (the core count) and 12, 8 interleaved runs each. All PRs were measured in the same batch, and every run ends at the same root.

master this PR Δ
finish @8 77.30 ± 0.98 ms 70.52 ± 0.45 ms −8.8%
into_overlay @8 55.32 ms 65.69 ms +19%
finish + into_overlay @8 132.6 ms 136.2 ms +2.7%
finish @12 64.26 ± 0.47 ms 57.37 ± 0.51 ms −10.7%
into_overlay @12 54.15 ms 65.35 ms +21%
finish + into_overlay @12 118.4 ms 122.7 ms +3.5%

Still a net loss end to end at both settings. More workers widen the finish gain, but into_overlay still pays about 10–11 ms more. On top of #950, #979, #987 and #988 at commit_concurrency 6 it was the same: finish 82.86 → 75.43 ms, into_overlay 54.22 → 66.09 ms.

Earlier, at commit_concurrency 6 on 12 pinned CPUs, against master df9f0e3:

master this PR Δ
finish_bench mean finish, 8 runs 102.39 ± 0.84 ms 95.58 ± 0.44 ms −6.7%
finish_bench mean into_overlay 55.44 ± 1.01 ms 67.14 ± 0.55 ms +21%
finish + into_overlay 157.8 ms 162.7 ms +3.1%

This is a net loss end to end on this benchmark. finish saves 6.8 ms, and into_overlay costs 11.7 ms more, even with the parallel freeze. It only pays off if into_overlay / commit is off the critical path. benchtop transfer (commit_and_prove, master / this PR, per round): 255 / 266, 264 / 267, 210 / 247, 195 / 217 ms. That is worse than master in all 4 rounds, but the rounds are noisy, see below.

finish_bench: an isolated Session::finish benchmark with the user-namespace access profile of a Sovereign SDK node (benchtop/src/bin/finish_bench.rs @ 3469d5c, not part of this PR). 50k–145k ReadThenWrite accesses per slot (68% updates with the prior value, 32% inserts), 36-byte values, BinaryHasher<Sha256>, rollback on, commit_concurrency 6, tree growing from 5.35M leaves, 10 warm-up + 20 measured slots from a restored seed DB. AMD Ryzen 7 7700, pinned to 12 threads. Base is master df9f0e3, measured in the same batch as #987, #988 and #989, with variant order rotated each round. Every run ends at the same root. benchtop transfer: -c 22 -s 20000 --commit-concurrency 4 --op-limit 3000000, 4 interleaved rounds on one DB copy. Its commit_and_prove moved from ~260 ms to ~200 ms for all variants between rounds 2 and 3, so it can't resolve differences this small.

🤖 Generated with Claude Code

citizen-stig and others added 3 commits November 18, 2026 10:09
… touches them

Walker stack pages are now CowPage: a fresh page, or a shared page plus the nodes changed in it. The 4 KiB copy of a shared page happens when UpdatedPages are frozen (into_overlay / commit), not in Session::finish.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
That mode now only serves tests, which compare whole reconstructed pages; copy-on-write
changed which recycled pool pages they saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With copy-on-write pages the 4 KiB copies happen in into_frozen_iter; spread them over threads
instead of copying ~85k pages serially in into_overlay / commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@citizen-stig
citizen-stig force-pushed the nikolai/cow-walker-pages branch from ee158e6 to 2514d01 Compare November 18, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants