From cb15303644a500df0affe8e553a83538ed614102 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 12 Jul 2024 02:05:22 +0000 Subject: [PATCH] perf(semantic): reduce memory copies (#4216) Reduce memory copies when resolving references in `Semantic`. If parent scope has no unresolved references for `name`, there is no need to generate a new `Vec` for `name` and copy in contents from current scope. Just move the existing `Vec` to the parent. --- crates/oxc_semantic/src/builder.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 4cd56c7d3..8fb3def8d 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -389,8 +389,10 @@ impl<'a> SemanticBuilder<'a> { self.symbols.references[*reference_id].set_symbol_id(symbol_id); } self.symbols.resolved_references[symbol_id].extend(reference_ids); + } else if let Some(parent_reference_ids) = parent_refs.get_mut(&name) { + parent_reference_ids.extend(reference_ids); } else { - parent_refs.entry(name).or_default().extend(reference_ids); + parent_refs.insert(name, reference_ids); } } }