execution/commitment: let trie warmup borrow branch bytes instead of copying them - #23585
Open
AskAlexSharov wants to merge 4 commits into
Open
execution/commitment: let trie warmup borrow branch bytes instead of copying them#23585AskAlexSharov wants to merge 4 commits into
AskAlexSharov wants to merge 4 commits into
Conversation
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
force-pushed
the
alex/warmup_borrowed_branch_37
branch
from
August 26, 2026 12:00
a202b8e to
52a6bae
Compare
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
marked this pull request as ready for review
August 27, 2026 05:06
AskAlexSharov
requested review from
awskii,
mh0lt and
taratorio
as code owners
August 27, 2026 05:06
taratorio
reviewed
Aug 27, 2026
| // 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) |
Member
There was a problem hiding this comment.
why not add this to the PatriciaContext interface?
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.
warmuper does read/copy/despose branch value. let's try to avoid