Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(trie): avoid (de)allocating an extra prefix set #13020

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion crates/trie/db/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX>
DatabaseTrieCursorFactory::new(tx),
DatabaseHashedCursorFactory::new(tx),
address,
Default::default(),
#[cfg(feature = "metrics")]
TrieRootMetrics::new(TrieType::Storage),
)
Expand All @@ -53,6 +54,7 @@ impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX>
DatabaseTrieCursorFactory::new(tx),
DatabaseHashedCursorFactory::new(tx),
hashed_address,
Default::default(),
#[cfg(feature = "metrics")]
TrieRootMetrics::new(TrieType::Storage),
)
Expand All @@ -70,10 +72,10 @@ impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX>
DatabaseTrieCursorFactory::new(tx),
HashedPostStateCursorFactory::new(DatabaseHashedCursorFactory::new(tx), &state_sorted),
address,
prefix_set,
#[cfg(feature = "metrics")]
TrieRootMetrics::new(TrieType::Storage),
)
.with_prefix_set(prefix_set)
.root()
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/trie/parallel/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ where
trie_cursor_factory,
hashed_state,
hashed_address,
prefix_set,
#[cfg(feature = "metrics")]
metrics,
)
.with_prefix_set(prefix_set)
.calculate(retain_updates)?)
})();
let _ = tx.send(result);
Expand Down Expand Up @@ -173,6 +173,7 @@ where
trie_cursor_factory.clone(),
hashed_cursor_factory.clone(),
hashed_address,
Default::default(),
#[cfg(feature = "metrics")]
self.metrics.storage_trie.clone(),
)
Expand Down
13 changes: 7 additions & 6 deletions crates/trie/trie/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,13 @@ where
self.trie_cursor_factory.clone(),
self.hashed_cursor_factory.clone(),
hashed_address,
#[cfg(feature = "metrics")]
self.metrics.storage_trie.clone(),
)
.with_prefix_set(
self.prefix_sets
.storage_prefix_sets
.get(&hashed_address)
.cloned()
.unwrap_or_default(),
#[cfg(feature = "metrics")]
self.metrics.storage_trie.clone(),
);

let storage_root = if retain_updates {
Expand Down Expand Up @@ -301,29 +299,32 @@ impl<T, H> StorageRoot<T, H> {
trie_cursor_factory: T,
hashed_cursor_factory: H,
address: Address,
prefix_set: PrefixSet,
#[cfg(feature = "metrics")] metrics: TrieRootMetrics,
) -> Self {
Self::new_hashed(
trie_cursor_factory,
hashed_cursor_factory,
keccak256(address),
prefix_set,
#[cfg(feature = "metrics")]
metrics,
)
}

/// Creates a new storage root calculator given a hashed address.
pub fn new_hashed(
pub const fn new_hashed(
trie_cursor_factory: T,
hashed_cursor_factory: H,
hashed_address: B256,
prefix_set: PrefixSet,
#[cfg(feature = "metrics")] metrics: TrieRootMetrics,
) -> Self {
Self {
trie_cursor_factory,
hashed_cursor_factory,
hashed_address,
prefix_set: PrefixSet::default(),
prefix_set,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, yeah this makes sense

#[cfg(feature = "metrics")]
metrics,
}
Expand Down
Loading