perf(trie): reserve capacity in apply_subtrie_update_actions (#22517)

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Georgios Konstantopoulos
2026-02-24 00:38:09 -08:00
committed by GitHub
parent 56bb47709c
commit d1cbf6ca5a

View File

@@ -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<Item = SparseTrieUpdatesAction>,
) {
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) => {