Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/trie/common/src/prefix_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ pub struct PrefixSet {

impl PrefixSet {
/// Returns `true` if any of the keys in the set has the given prefix
///
/// # Note on Mutability
///
/// This method requires `&mut self` (unlike typical `contains` methods) because it maintains an
/// internal position tracker (`self.index`) between calls. This enables significant performance
/// optimization for sequential lookups in sorted order, which is common during trie traversal.
///
/// The `index` field allows subsequent searches to start where previous ones left off,
/// avoiding repeated full scans of the prefix array when keys are accessed in nearby ranges.
///
/// This optimization was inspired by Silkworm's implementation and significantly improves
/// incremental state root calculation performance
/// ([see PR #2417](https://github.com/paradigmxyz/reth/pull/2417)).
#[inline]
pub fn contains(&mut self, prefix: &[u8]) -> bool {
if self.all {
Expand Down
Loading