From ea3d4663ae2550622040c1ff9b212bcfde04dfe3 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 20 Jan 2026 14:34:41 +0100 Subject: [PATCH] perf(trie): use HashMap reserve heuristic in MultiProof::extend (#21199) --- crates/trie/common/src/proofs.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/trie/common/src/proofs.rs b/crates/trie/common/src/proofs.rs index c3eab92011..b65b3ec966 100644 --- a/crates/trie/common/src/proofs.rs +++ b/crates/trie/common/src/proofs.rs @@ -267,6 +267,12 @@ impl MultiProof { self.account_subtree.extend_from(other.account_subtree); self.branch_node_masks.extend(other.branch_node_masks); + let reserve = if self.storages.is_empty() { + other.storages.len() + } else { + other.storages.len().div_ceil(2) + }; + self.storages.reserve(reserve); for (hashed_address, storage) in other.storages { match self.storages.entry(hashed_address) { hash_map::Entry::Occupied(mut entry) => { @@ -390,6 +396,12 @@ impl DecodedMultiProof { self.account_subtree.extend_from(other.account_subtree); self.branch_node_masks.extend(other.branch_node_masks); + let reserve = if self.storages.is_empty() { + other.storages.len() + } else { + other.storages.len().div_ceil(2) + }; + self.storages.reserve(reserve); for (hashed_address, storage) in other.storages { match self.storages.entry(hashed_address) { hash_map::Entry::Occupied(mut entry) => {