From d1cbf6ca5a08bb0fde5725b1e739edecfb40f5b7 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Tue, 24 Feb 2026 00:38:09 -0800 Subject: [PATCH] perf(trie): reserve capacity in apply_subtrie_update_actions (#22517) Co-authored-by: Amp --- crates/trie/sparse/src/parallel.rs | 4 ++++ 1 file changed, 4 insertions(+) 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) => {