diff --git a/crates/trie/sparse/src/parallel.rs b/crates/trie/sparse/src/parallel.rs index 8f83daa2d1..b8d413fb9d 100644 --- a/crates/trie/sparse/src/parallel.rs +++ b/crates/trie/sparse/src/parallel.rs @@ -999,6 +999,7 @@ impl SparseTrie for ParallelSparseTrie { // Sync branch_node_masks with what's being committed to DB. // This ensures that on subsequent root() calls, the masks reflect the actual // DB state, which is needed for correct removal detection. + self.branch_node_masks.reserve(updates.updated_nodes.len()); for (path, node) in &updates.updated_nodes { self.branch_node_masks.insert( *path, @@ -1854,6 +1855,9 @@ impl ParallelSparseTrie { update_actions: impl Iterator, ) { if let Some(updates) = self.updates.as_mut() { + let additional = update_actions.size_hint().0; + updates.updated_nodes.reserve(additional); + updates.removed_nodes.reserve(additional); for action in update_actions { match action { SparseTrieUpdatesAction::InsertRemoved(path) => {