Skip to content

Commit 30a869e

Browse files
committed
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.
1 parent bf4e5e1 commit 30a869e

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/oxc_semantic/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ oxc_span = { workspace = true }
3030
oxc_syntax = { workspace = true }
3131

3232
assert-unchecked = { workspace = true }
33-
hashbrown = { workspace = true, features = ["allocator-api2"] }
3433
itertools = { workspace = true }
3534
phf = { workspace = true, features = ["macros"] }
3635
rustc-hash = { workspace = true }

crates/oxc_semantic/src/builder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
712712
if self.scope.get_flags(parent_scope_id).is_catch_clause() {
713713
self.scope.cell.with_dependent_mut(|allocator, inner| {
714714
if !inner.bindings[parent_scope_id].is_empty() {
715-
let mut parent_bindings =
716-
Bindings::with_hasher_in(rustc_hash::FxBuildHasher, allocator);
715+
let mut parent_bindings = Bindings::new_in(allocator);
717716
mem::swap(&mut inner.bindings[parent_scope_id], &mut parent_bindings);
718717
for &symbol_id in parent_bindings.values() {
719718
self.symbols.set_scope_id(symbol_id, self.current_scope_id);

crates/oxc_semantic/src/scope.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::{fmt, mem};
22

3-
use rustc_hash::FxBuildHasher;
4-
5-
use oxc_allocator::{Allocator, Vec as ArenaVec};
3+
use oxc_allocator::{Allocator, HashMap as ArenaHashMap, Vec as ArenaVec};
64
use oxc_index::{Idx, IndexVec};
75
use oxc_syntax::{
86
node::NodeId,
@@ -13,9 +11,8 @@ use oxc_syntax::{
1311

1412
use crate::SymbolTable;
1513

16-
pub(crate) type Bindings<'a> = hashbrown::HashMap<&'a str, SymbolId, FxBuildHasher, &'a Allocator>;
17-
pub type UnresolvedReferences<'a> =
18-
hashbrown::HashMap<&'a str, ArenaVec<'a, ReferenceId>, FxBuildHasher, &'a Allocator>;
14+
pub(crate) type Bindings<'a> = ArenaHashMap<'a, &'a str, SymbolId>;
15+
pub type UnresolvedReferences<'a> = ArenaHashMap<'a, &'a str, ArenaVec<'a, ReferenceId>>;
1916

2017
/// Scope Tree
2118
///
@@ -58,10 +55,7 @@ impl Default for ScopeTree {
5855
cell: ScopeTreeCell::new(Allocator::default(), |allocator| ScopeTreeInner {
5956
bindings: IndexVec::new(),
6057
child_ids: ArenaVec::new_in(allocator),
61-
root_unresolved_references: UnresolvedReferences::with_hasher_in(
62-
FxBuildHasher,
63-
allocator,
64-
),
58+
root_unresolved_references: UnresolvedReferences::new_in(allocator),
6559
}),
6660
}
6761
}
@@ -384,7 +378,7 @@ impl ScopeTree {
384378
let scope_id = self.parent_ids.push(parent_id);
385379
self.flags.push(flags);
386380
self.cell.with_dependent_mut(|allocator, inner| {
387-
inner.bindings.push(Bindings::with_hasher_in(FxBuildHasher, allocator));
381+
inner.bindings.push(Bindings::new_in(allocator));
388382
});
389383
self.node_ids.push(node_id);
390384
if self.build_child_ids {

0 commit comments

Comments
 (0)