mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
perf: reduce update_leaves key cloning (#22228)
This commit is contained in:
@@ -1322,14 +1322,12 @@ impl SparseTrie for ParallelSparseTrie {
|
||||
) -> SparseTrieResult<()> {
|
||||
use crate::{provider::NoRevealProvider, LeafUpdate};
|
||||
|
||||
// Collect keys upfront since we mutate `updates` during iteration.
|
||||
// On success, entries are removed; on blinded node failure, they're re-inserted.
|
||||
let keys: Vec<B256> = updates.keys().copied().collect();
|
||||
// Drain updates to avoid cloning keys while preserving the map's allocation.
|
||||
// On success, entries remain removed; on blinded node failure, they're re-inserted.
|
||||
let drained: Vec<_> = updates.drain().collect();
|
||||
|
||||
for key in keys {
|
||||
for (key, update) in drained {
|
||||
let full_path = Nibbles::unpack(key);
|
||||
// Remove upfront - we'll re-insert if the operation fails due to blinded node.
|
||||
let update = updates.remove(&key).unwrap();
|
||||
|
||||
match update {
|
||||
LeafUpdate::Changed(value) => {
|
||||
|
||||
Reference in New Issue
Block a user