perf(trie): reuse account RLP buffer in SparseTrieCacheTask#21644
Merged
perf(trie): reuse account RLP buffer in SparseTrieCacheTask#21644
Conversation
Add account_rlp_buf field to SparseTrieCacheTask, pre-allocated with TRIE_ACCOUNT_RLP_MAX_SIZE. Replace alloy_rlp::encode() calls with clear() + encode(&mut buf) + clone() pattern to avoid repeated heap allocations during account encoding.
mattsse
requested changes
Jan 30, 2026
Comment on lines
533
to
536
| let storage_updates = &self.storage_updates; | ||
| let account_updates = &mut self.account_updates; | ||
| let trie = &mut self.trie; | ||
| let account_rlp_buf = &mut self.account_rlp_buf; |
Collaborator
There was a problem hiding this comment.
why do we need to do this, this shouldnt conflict with the borrow checker because we can access the fields separately
Amp-Thread-ID: https://ampcode.com/threads/T-019c109d-8369-77db-abff-d8af52126b1d Co-authored-by: Amp <[email protected]>
mattsse
approved these changes
Jan 30, 2026
klkvr
approved these changes
Feb 1, 2026
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.
Summary
Adds a reusable
account_rlp_buffield toSparseTrieCacheTask, pre-allocated withTRIE_ACCOUNT_RLP_MAX_SIZE, to avoid repeated heap allocations when encoding accounts.Changes
account_rlp_buf: Vec<u8>field toSparseTrieCacheTaskTRIE_ACCOUNT_RLP_MAX_SIZEin constructoralloy_rlp::encode()calls withclear(); encode(&mut buf); buf.clone()Testing
cargo check -p reth-engine-treeand clippy pass.