Skip to content

beatree: skip the unread staging map during sync - #999

Draft
citizen-stig wants to merge 5 commits into
thrumdev:masterfrom
citizen-stig:autoresearchresult-sov-commit-1s-02-staging-bypass
Draft

citizen-stig wants to merge 5 commits into
thrumdev:masterfrom
citizen-stig:autoresearchresult-sov-commit-1s-02-staging-bypass

Conversation

@citizen-stig

Copy link
Copy Markdown
Contributor

What changed

beatree::SyncController::begin_sync now collects and sorts the changeset and passes it straight to Tree::prepare_sync → ops::update → leaf_stage::run. The leaf stage takes the values by move instead of cloning them. Tree::commit and Shared::take_staged_changeset are removed. The staging fields stay, so the read path is unchanged.

Why it is faster

Every sync inserted its changeset into an imbl::OrdMap staging map before any leaf could be written: about 11 ms of CPU for 40k entries, on the critical path. Nothing reads that map during a commit, because every reader takes access_lock for reading and Overlay::commit holds it for writing for the whole commit. The rollback session, which skips the guard, runs on the thread that already holds the write lock.

Measured

Stock benchtop, ~33.5M keys, 39k random writes per block (1/3 inserts), commit_concurrency 8, 64M preallocated buckets, rollback on:

durable_commit
master 154 ms
this PR 142 ms (−7.8%)

Same final root.

…staging it

Readers are excluded while a commit runs (every reader takes access_lock for
reading and Overlay::commit holds it for writing), so the imbl staging map
built in Tree::commit was never read. Collect and sort the changeset and
pass it to ops::update; the leaf stage takes the values by move instead of
cloning them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@citizen-stig
citizen-stig marked this pull request as draft November 24, 2026 13:48
citizen-stig and others added 4 commits November 24, 2026 18:33
Session::finish checked that actuals are strictly sorted only under
debug_assertions. Without them a repeated key went through: the trie kept
the first write while the value store kept another, so the committed root
disagreed with the stored values. Return an error instead.

Reported as A4-3 and A7-10 in the 2026-11-23 audit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017wb3qH3B6abyFmZUHWkjxH
The update assumes each key appears once. The staging map used to collapse
repeats; now the changeset goes straight to the update, so check for them
after sorting and fail the sync instead of writing a duplicate cell.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017wb3qH3B6abyFmZUHWkjxH
Since changes go straight to the update, primary_staging is always empty
and secondary_staging always None. Drop both, their lookups, and the
staging merge in BeatreeIterator, including the unsafe OrdMap cursor.

Lookups and read transactions see the tree as of the last finished sync;
say so in the docs. Explain why prepare_sync keeps the write lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017wb3qH3B6abyFmZUHWkjxH
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