Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

perf(trie): reuse account RLP buffer in SparseTrieCacheTask#21644

Merged
klkvr merged 2 commits intomainfrom
mattsse/account-rlp-buf
Feb 1, 2026
Merged

perf(trie): reuse account RLP buffer in SparseTrieCacheTask#21644
klkvr merged 2 commits intomainfrom
mattsse/account-rlp-buf

Conversation

@gakonst
Copy link
Member

@gakonst gakonst commented Jan 30, 2026

Summary

Adds a reusable account_rlp_buf field to SparseTrieCacheTask, pre-allocated with TRIE_ACCOUNT_RLP_MAX_SIZE, to avoid repeated heap allocations when encoding accounts.

Changes

  • Added account_rlp_buf: Vec<u8> field to SparseTrieCacheTask
  • Pre-allocate buffer with TRIE_ACCOUNT_RLP_MAX_SIZE in constructor
  • Replace alloy_rlp::encode() calls with clear(); encode(&mut buf); buf.clone()
  • Removed TODO comments

Testing

cargo check -p reth-engine-tree and clippy pass.

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.
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Jan 30, 2026
@gakonst gakonst added A-trie Related to Merkle Patricia Trie implementation A-engine Related to the engine implementation labels 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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need to do this, this shouldnt conflict with the borrow checker because we can access the fields separately

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Jan 30, 2026
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm, pending @klkvr

@mattsse mattsse marked this pull request as ready for review January 30, 2026 20:54
@klkvr klkvr added this pull request to the merge queue Feb 1, 2026
Merged via the queue into main with commit 3d699ac Feb 1, 2026
47 checks passed
@klkvr klkvr deleted the mattsse/account-rlp-buf branch February 1, 2026 15:32
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-engine Related to the engine implementation A-trie Related to Merkle Patricia Trie implementation

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants