perf(semantic): use oxc_allocator::HashMap in ScopeTree (#8554)

Use `oxc_allocator::HashMap` in `ScopeTree`, replacing `hashbrown::HashMap`. `oxc_allocator::HashMap` is non-drop, so it may reduce drop time of `ScopeTree` a little.
This commit is contained in:
overlookmotel 2025-01-16 23:29:57 +00:00
parent bf4e5e1c18
commit 30a869ead2
4 changed files with 6 additions and 15 deletions

1
Cargo.lock generated
View file

@ -2034,7 +2034,6 @@ name = "oxc_semantic"
version = "0.46.0"
dependencies = [
"assert-unchecked",
"hashbrown 0.15.2",
"insta",
"itertools",
"oxc_allocator",

View file

@ -30,7 +30,6 @@ oxc_span = { workspace = true }
oxc_syntax = { workspace = true }
assert-unchecked = { workspace = true }
hashbrown = { workspace = true, features = ["allocator-api2"] }
itertools = { workspace = true }
phf = { workspace = true, features = ["macros"] }
rustc-hash = { workspace = true }

View file

@ -712,8 +712,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
if self.scope.get_flags(parent_scope_id).is_catch_clause() {
self.scope.cell.with_dependent_mut(|allocator, inner| {
if !inner.bindings[parent_scope_id].is_empty() {
let mut parent_bindings =
Bindings::with_hasher_in(rustc_hash::FxBuildHasher, allocator);
let mut parent_bindings = Bindings::new_in(allocator);
mem::swap(&mut inner.bindings[parent_scope_id], &mut parent_bindings);
for &symbol_id in parent_bindings.values() {
self.symbols.set_scope_id(symbol_id, self.current_scope_id);

View file

@ -1,8 +1,6 @@
use std::{fmt, mem};
use rustc_hash::FxBuildHasher;
use oxc_allocator::{Allocator, Vec as ArenaVec};
use oxc_allocator::{Allocator, HashMap as ArenaHashMap, Vec as ArenaVec};
use oxc_index::{Idx, IndexVec};
use oxc_syntax::{
node::NodeId,
@ -13,9 +11,8 @@ use oxc_syntax::{
use crate::SymbolTable;
pub(crate) type Bindings<'a> = hashbrown::HashMap<&'a str, SymbolId, FxBuildHasher, &'a Allocator>;
pub type UnresolvedReferences<'a> =
hashbrown::HashMap<&'a str, ArenaVec<'a, ReferenceId>, FxBuildHasher, &'a Allocator>;
pub(crate) type Bindings<'a> = ArenaHashMap<'a, &'a str, SymbolId>;
pub type UnresolvedReferences<'a> = ArenaHashMap<'a, &'a str, ArenaVec<'a, ReferenceId>>;
/// Scope Tree
///
@ -58,10 +55,7 @@ impl Default for ScopeTree {
cell: ScopeTreeCell::new(Allocator::default(), |allocator| ScopeTreeInner {
bindings: IndexVec::new(),
child_ids: ArenaVec::new_in(allocator),
root_unresolved_references: UnresolvedReferences::with_hasher_in(
FxBuildHasher,
allocator,
),
root_unresolved_references: UnresolvedReferences::new_in(allocator),
}),
}
}
@ -384,7 +378,7 @@ impl ScopeTree {
let scope_id = self.parent_ids.push(parent_id);
self.flags.push(flags);
self.cell.with_dependent_mut(|allocator, inner| {
inner.bindings.push(Bindings::with_hasher_in(FxBuildHasher, allocator));
inner.bindings.push(Bindings::new_in(allocator));
});
self.node_ids.push(node_id);
if self.build_child_ids {