Skip to content

Commit

Permalink
perf(semantic): reduce memory copies (#4216)
Browse files Browse the repository at this point in the history
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<ReferenceId>` for `name` and copy in contents from current scope. Just move the existing `Vec` to the parent.
  • Loading branch information
overlookmotel committed Jul 12, 2024
1 parent ef4c1f4 commit cb15303
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit cb15303

Please sign in to comment.