Skip to content

execution/commitment: let trie warmup borrow branch bytes instead of copying them - #23585

Open
AskAlexSharov wants to merge 4 commits into
mainfrom
alex/warmup_borrowed_branch_37
Open

execution/commitment: let trie warmup borrow branch bytes instead of copying them#23585
AskAlexSharov wants to merge 4 commits into
mainfrom
alex/warmup_borrowed_branch_37

Conversation

@AskAlexSharov

@AskAlexSharov AskAlexSharov commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

warmuper does read/copy/despose branch value. let's try to avoid

TrieContext.Branch copies every branch it reads, because the trie's own consumers
retain the bytes past the read: Merge, the encoder and merger buffers, and the
deferred-update queues. Warmup retains nothing -- it pulls the child bitmap, a
byte of field bits per cell and an extension length, all scalars, to pick the next
nibble -- yet it pays the same copy, and it issues several times more branch reads
than the fold does.

WarmupBranch hands back the read uncopied. The bytes stay valid for the life of
the context's transaction: mdbx guarantees that for a read, mmapped .kv pages are
pinned by it, and the mem batch and the branch/state caches all store heap-owned
values. Callers that keep branch data stay on Branch.

Selected once per warmup worker rather than per key, so the interface assertion
and the method value stay off the per-key path.
@AskAlexSharov
AskAlexSharov force-pushed the alex/warmup_borrowed_branch_37 branch from a202b8e to 52a6bae Compare August 26, 2026 12:00
The name now says what it does. The doc says what the caller owes: the result
aliases the reader's memory and must not be retained or mutated. Branch copies
because the trie's consumers do both, not because the source is short-lived.
…xt-call

The tighter promise leaves the reader free to hand back a reused buffer later.
The fake now poisons what the previous call returned, so a caller that keeps the
bytes across a read descends differently and the test fails.
@AskAlexSharov
AskAlexSharov marked this pull request as ready for review August 27, 2026 05:06
// not be mutated. Branch copies because the trie's consumers keep branch data
// past that.
type BranchNoCopyReader interface {
BranchNoCopy(prefix []byte) ([]byte, kv.Step, error)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not add this to the PatriciaContext interface?

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