Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading