mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf(trie): avoid (de)allocating an extra prefix set (#13020)
This commit is contained in:
@ -43,6 +43,7 @@ impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX>
|
|||||||
DatabaseTrieCursorFactory::new(tx),
|
DatabaseTrieCursorFactory::new(tx),
|
||||||
DatabaseHashedCursorFactory::new(tx),
|
DatabaseHashedCursorFactory::new(tx),
|
||||||
address,
|
address,
|
||||||
|
Default::default(),
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
TrieRootMetrics::new(TrieType::Storage),
|
TrieRootMetrics::new(TrieType::Storage),
|
||||||
)
|
)
|
||||||
@ -53,6 +54,7 @@ impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX>
|
|||||||
DatabaseTrieCursorFactory::new(tx),
|
DatabaseTrieCursorFactory::new(tx),
|
||||||
DatabaseHashedCursorFactory::new(tx),
|
DatabaseHashedCursorFactory::new(tx),
|
||||||
hashed_address,
|
hashed_address,
|
||||||
|
Default::default(),
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
TrieRootMetrics::new(TrieType::Storage),
|
TrieRootMetrics::new(TrieType::Storage),
|
||||||
)
|
)
|
||||||
@ -70,10 +72,10 @@ impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX>
|
|||||||
DatabaseTrieCursorFactory::new(tx),
|
DatabaseTrieCursorFactory::new(tx),
|
||||||
HashedPostStateCursorFactory::new(DatabaseHashedCursorFactory::new(tx), &state_sorted),
|
HashedPostStateCursorFactory::new(DatabaseHashedCursorFactory::new(tx), &state_sorted),
|
||||||
address,
|
address,
|
||||||
|
prefix_set,
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
TrieRootMetrics::new(TrieType::Storage),
|
TrieRootMetrics::new(TrieType::Storage),
|
||||||
)
|
)
|
||||||
.with_prefix_set(prefix_set)
|
|
||||||
.root()
|
.root()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,10 +121,10 @@ where
|
|||||||
trie_cursor_factory,
|
trie_cursor_factory,
|
||||||
hashed_state,
|
hashed_state,
|
||||||
hashed_address,
|
hashed_address,
|
||||||
|
prefix_set,
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
metrics,
|
metrics,
|
||||||
)
|
)
|
||||||
.with_prefix_set(prefix_set)
|
|
||||||
.calculate(retain_updates)?)
|
.calculate(retain_updates)?)
|
||||||
})();
|
})();
|
||||||
let _ = tx.send(result);
|
let _ = tx.send(result);
|
||||||
@ -179,6 +179,7 @@ where
|
|||||||
trie_cursor_factory.clone(),
|
trie_cursor_factory.clone(),
|
||||||
hashed_cursor_factory.clone(),
|
hashed_cursor_factory.clone(),
|
||||||
hashed_address,
|
hashed_address,
|
||||||
|
Default::default(),
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
self.metrics.storage_trie.clone(),
|
self.metrics.storage_trie.clone(),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -202,15 +202,13 @@ where
|
|||||||
self.trie_cursor_factory.clone(),
|
self.trie_cursor_factory.clone(),
|
||||||
self.hashed_cursor_factory.clone(),
|
self.hashed_cursor_factory.clone(),
|
||||||
hashed_address,
|
hashed_address,
|
||||||
#[cfg(feature = "metrics")]
|
|
||||||
self.metrics.storage_trie.clone(),
|
|
||||||
)
|
|
||||||
.with_prefix_set(
|
|
||||||
self.prefix_sets
|
self.prefix_sets
|
||||||
.storage_prefix_sets
|
.storage_prefix_sets
|
||||||
.get(&hashed_address)
|
.get(&hashed_address)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
|
#[cfg(feature = "metrics")]
|
||||||
|
self.metrics.storage_trie.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let storage_root = if retain_updates {
|
let storage_root = if retain_updates {
|
||||||
@ -301,29 +299,32 @@ impl<T, H> StorageRoot<T, H> {
|
|||||||
trie_cursor_factory: T,
|
trie_cursor_factory: T,
|
||||||
hashed_cursor_factory: H,
|
hashed_cursor_factory: H,
|
||||||
address: Address,
|
address: Address,
|
||||||
|
prefix_set: PrefixSet,
|
||||||
#[cfg(feature = "metrics")] metrics: TrieRootMetrics,
|
#[cfg(feature = "metrics")] metrics: TrieRootMetrics,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_hashed(
|
Self::new_hashed(
|
||||||
trie_cursor_factory,
|
trie_cursor_factory,
|
||||||
hashed_cursor_factory,
|
hashed_cursor_factory,
|
||||||
keccak256(address),
|
keccak256(address),
|
||||||
|
prefix_set,
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
metrics,
|
metrics,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new storage root calculator given a hashed address.
|
/// Creates a new storage root calculator given a hashed address.
|
||||||
pub fn new_hashed(
|
pub const fn new_hashed(
|
||||||
trie_cursor_factory: T,
|
trie_cursor_factory: T,
|
||||||
hashed_cursor_factory: H,
|
hashed_cursor_factory: H,
|
||||||
hashed_address: B256,
|
hashed_address: B256,
|
||||||
|
prefix_set: PrefixSet,
|
||||||
#[cfg(feature = "metrics")] metrics: TrieRootMetrics,
|
#[cfg(feature = "metrics")] metrics: TrieRootMetrics,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
trie_cursor_factory,
|
trie_cursor_factory,
|
||||||
hashed_cursor_factory,
|
hashed_cursor_factory,
|
||||||
hashed_address,
|
hashed_address,
|
||||||
prefix_set: PrefixSet::default(),
|
prefix_set,
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
metrics,
|
metrics,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user