Repository navigation
merkle: copy walker pages on freeze, and freeze them in parallel - #989
Draft
citizen-stig wants to merge 3 commits into
Draft
citizen-stig wants to merge 3 commits into
citizen-stig wants to merge 3 commits into
Conversation
This was referenced Nov 18, 2026
… 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
force-pushed
the
nikolai/cow-walker-pages
branch
from
November 18, 2026 09:39
ee158e6 to
2514d01
Compare
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
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).UpdatedPages::into_frozen_iterfreezes the per-worker page lists in parallel, so the copies that moved intointo_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
finishcritical path.The copy moves out of
finish; it doesn't disappear. Read the benchmarks withfinishandinto_overlaytogether.Notes
merkle/page_walker.rs. Whichever PR merges second gets rebased. If merkle: rebuild elided pages directly from the sorted leaves #979 merges first, the eager-copy branch instack_pagecan go too, since merkle: rebuild elided pages directly from the sorted leaves #979 removes the walker's reconstruction mode.Benchmarks
finish_benchon all 16 CPUs (8 cores) against master6ee36d3, atcommit_concurrency8 (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.finish@8into_overlay@8finish+into_overlay@8finish@12into_overlay@12finish+into_overlay@12Still a net loss end to end at both settings. More workers widen the
finishgain, butinto_overlaystill pays about 10–11 ms more. On top of #950, #979, #987 and #988 atcommit_concurrency6 it was the same:finish82.86 → 75.43 ms,into_overlay54.22 → 66.09 ms.Earlier, at
commit_concurrency6 on 12 pinned CPUs, against masterdf9f0e3:finish_benchmeanfinish, 8 runsfinish_benchmeaninto_overlayfinish+into_overlayThis is a net loss end to end on this benchmark.
finishsaves 6.8 ms, andinto_overlaycosts 11.7 ms more, even with the parallel freeze. It only pays off ifinto_overlay/ commit is off the critical path.benchtoptransfer (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 isolatedSession::finishbenchmark with the user-namespace access profile of a Sovereign SDK node (benchtop/src/bin/finish_bench.rs@ 3469d5c, not part of this PR). 50k–145kReadThenWriteaccesses per slot (68% updates with the prior value, 32% inserts), 36-byte values,BinaryHasher<Sha256>, rollback on,commit_concurrency6, 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 masterdf9f0e3, measured in the same batch as #987, #988 and #989, with variant order rotated each round. Every run ends at the same root.benchtoptransfer:-c 22 -s 20000 --commit-concurrency 4 --op-limit 3000000, 4 interleaved rounds on one DB copy. Itscommit_and_provemoved 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