Skip to content

Commit

Permalink
perf(semantic): use oxc_allocator::HashMap in ScopeTree (#8554)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
overlookmotel committed Jan 16, 2025
1 parent bf4e5e1 commit 30a869e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/oxc_semantic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 5 additions & 11 deletions crates/oxc_semantic/src/scope.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
///
Expand Down Expand Up @@ -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),
}),
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 30a869e

Please sign in to comment.