Skip to content

Commit b43e38d

Browse files
authoredAug 16, 2023
refactor: Use ahash from swc_common in more places (#7815)
**Description:** Uses ahash from swc_common in more places. This allows for more easily swapping out ahash with rustc_hash.
1 parent 2dc88ef commit b43e38d

File tree

40 files changed

+82
-88
lines changed

40 files changed

+82
-88
lines changed
 

‎Cargo.lock

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

‎crates/swc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ plugin_transform_host_native = [
4848
]
4949

5050
[dependencies]
51-
ahash = "0.8.3"
5251
anyhow = "1"
5352
base64 = "0.13.0"
5453
dashmap = "5.4.0"

‎crates/swc/src/config/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use swc_atoms::JsWord;
2424
use swc_cached::regex::CachedRegex;
2525
use swc_common::{
2626
chain,
27-
collections::{AHashMap, AHashSet},
27+
collections::{AHashMap, AHashSet, ARandomState},
2828
comments::{Comments, SingleThreadedComments},
2929
errors::Handler,
3030
plugin::metadata::TransformPluginMetadataContext,
@@ -1497,7 +1497,7 @@ impl Default for ErrorFormat {
14971497
}
14981498

14991499
/// `paths` section of `tsconfig.json`.
1500-
pub type Paths = IndexMap<String, Vec<String>, ahash::RandomState>;
1500+
pub type Paths = IndexMap<String, Vec<String>, ARandomState>;
15011501
pub(crate) type CompiledPaths = Vec<(String, Vec<String>)>;
15021502

15031503
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -1746,7 +1746,7 @@ pub struct ErrorConfig {
17461746
#[serde(deny_unknown_fields, rename_all = "camelCase")]
17471747
pub struct GlobalPassOption {
17481748
#[serde(default)]
1749-
pub vars: IndexMap<JsWord, JsWord, ahash::RandomState>,
1749+
pub vars: IndexMap<JsWord, JsWord, ARandomState>,
17501750
#[serde(default)]
17511751
pub envs: GlobalInliningPassEnvs,
17521752

@@ -1826,7 +1826,7 @@ impl GlobalPassOption {
18261826
} else {
18271827
match &self.envs {
18281828
GlobalInliningPassEnvs::List(env_list) => {
1829-
static CACHE: Lazy<DashMap<Vec<String>, ValuesMap, ahash::RandomState>> =
1829+
static CACHE: Lazy<DashMap<Vec<String>, ValuesMap, ARandomState>> =
18301830
Lazy::new(Default::default);
18311831

18321832
let cache_key = env_list.iter().cloned().collect::<Vec<_>>();
@@ -1847,9 +1847,8 @@ impl GlobalPassOption {
18471847
}
18481848

18491849
GlobalInliningPassEnvs::Map(map) => {
1850-
static CACHE: Lazy<
1851-
DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ahash::RandomState>,
1852-
> = Lazy::new(Default::default);
1850+
static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ARandomState>> =
1851+
Lazy::new(Default::default);
18531852

18541853
let cache_key = self
18551854
.vars
@@ -1873,7 +1872,7 @@ impl GlobalPassOption {
18731872
};
18741873

18751874
let global_exprs = {
1876-
static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, GlobalExprMap, ahash::RandomState>> =
1875+
static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, GlobalExprMap, ARandomState>> =
18771876
Lazy::new(Default::default);
18781877

18791878
let cache_key = self
@@ -1904,7 +1903,7 @@ impl GlobalPassOption {
19041903
};
19051904

19061905
let global_map = {
1907-
static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ahash::RandomState>> =
1906+
static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ARandomState>> =
19081907
Lazy::new(Default::default);
19091908

19101909
let cache_key = self
@@ -1943,7 +1942,7 @@ fn default_env_name() -> String {
19431942
}
19441943

19451944
fn build_resolver(base_url: PathBuf, paths: CompiledPaths) -> Box<SwcImportResolver> {
1946-
static CACHE: Lazy<DashMap<(PathBuf, CompiledPaths), SwcImportResolver, ahash::RandomState>> =
1945+
static CACHE: Lazy<DashMap<(PathBuf, CompiledPaths), SwcImportResolver, ARandomState>> =
19471946
Lazy::new(Default::default);
19481947

19491948
if let Some(cached) = CACHE.get(&(base_url.clone(), paths.clone())) {

‎crates/swc_bundler/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ concurrent = ["swc_common/concurrent", "dashmap", "rayon", "indexmap/rayon"]
2424
default = []
2525

2626
[dependencies]
27-
ahash = "0.8"
2827
anyhow = "1"
2928
crc = "2.1.0"
3029
dashmap = { version = "5.4.0", optional = true }

‎crates/swc_bundler/src/bundler/chunk/merge.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use indexmap::IndexSet;
55
use petgraph::EdgeDirection;
66
use swc_atoms::js_word;
77
use swc_common::{
8-
collections::{AHashMap, AHashSet},
8+
collections::{AHashMap, AHashSet, ARandomState},
99
sync::Lock,
1010
FileName, SyntaxContext, DUMMY_SP,
1111
};
@@ -138,7 +138,7 @@ where
138138
graph: &ModuleGraph,
139139
start: ModuleId,
140140
dejavu: &mut AHashSet<ModuleId>,
141-
) -> IndexSet<ModuleId, ahash::RandomState> {
141+
) -> IndexSet<ModuleId, ARandomState> {
142142
let mut set = IndexSet::default();
143143

144144
for dep in graph.neighbors_directed(start, Outgoing) {

‎crates/swc_bundler/src/bundler/export.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use indexmap::IndexMap;
22
use swc_atoms::{js_word, JsWord};
3-
use swc_common::{FileName, SyntaxContext};
3+
use swc_common::{collections::ARandomState, FileName, SyntaxContext};
44
use swc_ecma_ast::*;
55
use swc_ecma_utils::find_pat_ids;
66
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
@@ -42,7 +42,7 @@ where
4242
#[derive(Debug, Default)]
4343
pub(super) struct RawExports {
4444
/// Key is None if it's exported from the module itself.
45-
pub items: IndexMap<Option<Str>, Vec<Specifier>, ahash::RandomState>,
45+
pub items: IndexMap<Option<Str>, Vec<Specifier>, ARandomState>,
4646
}
4747

4848
#[derive(Debug, Default)]

‎crates/swc_bundler/src/bundler/finalize.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::path::{Path, PathBuf};
22

3-
use ahash::AHashMap;
43
use anyhow::Error;
54
use relative_path::RelativePath;
65
use swc_atoms::js_word;
7-
use swc_common::{util::move_map::MoveMap, FileName, Mark, DUMMY_SP};
6+
use swc_common::{collections::AHashMap, util::move_map::MoveMap, FileName, Mark, DUMMY_SP};
87
use swc_ecma_ast::*;
98
use swc_ecma_transforms_base::{
109
fixer::fixer,

‎crates/swc_bundler/src/bundler/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33

44
use anyhow::Error;
55
use indexmap::IndexMap;
6-
use swc_common::{sync::Lrc, FileName, SourceMap, Span, GLOBALS};
6+
use swc_common::{collections::ARandomState, sync::Lrc, FileName, SourceMap, Span, GLOBALS};
77
use swc_ecma_ast::*;
88
use swc_ecma_parser::{lexer::Lexer, Parser, StringInput};
99
use swc_ecma_utils::drop_span;
@@ -19,7 +19,7 @@ pub(crate) struct Tester<'a> {
1919

2020
pub struct Loader {
2121
cm: Lrc<SourceMap>,
22-
files: IndexMap<String, String, ahash::RandomState>,
22+
files: IndexMap<String, String, ARandomState>,
2323
}
2424

2525
impl Load for Loader {
@@ -108,7 +108,7 @@ pub(crate) fn suite() -> TestBuilder {
108108

109109
#[derive(Default)]
110110
pub(crate) struct TestBuilder {
111-
files: IndexMap<String, String, ahash::RandomState>,
111+
files: IndexMap<String, String, ARandomState>,
112112
}
113113

114114
impl TestBuilder {

‎crates/swc_bundler/src/modules/sort/chunk.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use std::{collections::VecDeque, iter::from_fn, mem::take, time::Instant};
22

33
use indexmap::IndexSet;
44
use petgraph::EdgeDirection::Outgoing;
5-
use swc_common::{collections::AHashSet, sync::Lrc, SourceMap, SyntaxContext};
5+
use swc_common::{
6+
collections::{AHashSet, ARandomState},
7+
sync::Lrc,
8+
SourceMap, SyntaxContext,
9+
};
610
use swc_ecma_ast::*;
711
use swc_ecma_utils::prepend_stmts;
812

@@ -133,7 +137,7 @@ fn cycles_for(
133137
cycles: &[Vec<ModuleId>],
134138
id: ModuleId,
135139
checked: &mut Vec<ModuleId>,
136-
) -> IndexSet<ModuleId, ahash::RandomState> {
140+
) -> IndexSet<ModuleId, ARandomState> {
137141
checked.push(id);
138142
let mut v = cycles
139143
.iter()

‎crates/swc_bundler/src/modules/sort/stmt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use indexmap::IndexSet;
44
use petgraph::EdgeDirection::{Incoming as Dependants, Outgoing as Dependencies};
55
use swc_atoms::js_word;
66
use swc_common::{
7-
collections::{AHashMap, AHashSet},
7+
collections::{AHashMap, AHashSet, ARandomState},
88
sync::Lrc,
99
util::take::Take,
1010
SourceMap, Spanned, SyntaxContext,
@@ -501,11 +501,11 @@ impl Visit for InitializerFinder {
501501
/// But we care about modifications.
502502
#[derive(Default)]
503503
struct RequirementCalculator {
504-
required_ids: IndexSet<(Id, Required), ahash::RandomState>,
504+
required_ids: IndexSet<(Id, Required), ARandomState>,
505505
/// While bundling, there can be two bindings with same name and syntax
506506
/// context, in case of wrapped es modules. We exclude them from dependency
507507
/// graph.
508-
excluded: IndexSet<Id, ahash::RandomState>,
508+
excluded: IndexSet<Id, ARandomState>,
509509

510510
in_weak: bool,
511511
in_var_decl: bool,

‎crates/swc_bundler/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ where
101101
V: Clone,
102102
{
103103
#[cfg(feature = "concurrent")]
104-
inner: dashmap::DashMap<K, V, ahash::RandomState>,
104+
inner: dashmap::DashMap<K, V, swc_common::collections::ARandomState>,
105105
#[cfg(not(feature = "concurrent"))]
106106
inner: std::cell::RefCell<swc_common::collections::AHashMap<K, V>>,
107107
}

‎crates/swc_common/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ concurrent = ["parking_lot"]
2323
debug = []
2424
default = []
2525
diagnostic-serde = []
26-
perf = ["parking_lot"]
26+
perf = []
2727
plugin-base = ["__plugin", "anyhow", "rkyv-impl", "diagnostic-serde"]
2828
plugin-mode = ["__plugin_mode", "plugin-base"]
2929
plugin-rt = ["__plugin_rt", "plugin-base"]

‎crates/swc_common/src/collections.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ mod fxhash {
1212

1313
use rustc_hash::FxHasher;
1414

15-
pub type AHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
15+
pub type ARandomState = BuildHasherDefault<FxHasher>;
1616

17-
pub type AHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
17+
pub type AHashMap<K, V> = HashMap<K, V, ARandomState>;
18+
19+
pub type AHashSet<V> = HashSet<V, ARandomState>;
1820
}
1921

2022
#[cfg(not(feature = "perf"))]
2123
mod ahash {
2224
use std::collections::{HashMap, HashSet};
2325

24-
pub type AHashMap<K, V> = HashMap<K, V, ahash::RandomState>;
26+
pub type ARandomState = ahash::RandomState;
27+
28+
pub type AHashMap<K, V> = HashMap<K, V, ARandomState>;
2529

26-
pub type AHashSet<V> = HashSet<V, ahash::RandomState>;
30+
pub type AHashSet<V> = HashSet<V, ARandomState>;
2731
}

‎crates/swc_ecma_lints/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ version = "0.85.21"
1313
bench = false
1414

1515
[dependencies]
16-
ahash = "0.8"
1716
auto_impl = "1.1.0"
1817
dashmap = "5.4.0"
1918
parking_lot = "0.12.1"

‎crates/swc_ecma_lints/src/rules/dot_notation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use dashmap::DashMap;
22
use regex::Regex;
33
use serde::{Deserialize, Serialize};
4-
use swc_common::{errors::HANDLER, sync::Lazy, Span};
4+
use swc_common::{collections::ARandomState, errors::HANDLER, sync::Lazy, Span};
55
use swc_ecma_ast::*;
66
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
77

@@ -76,7 +76,7 @@ impl DotNotation {
7676
}
7777

7878
if let Some(pattern) = &self.pattern {
79-
static REGEX_CACHE: Lazy<DashMap<String, Regex, ahash::RandomState>> =
79+
static REGEX_CACHE: Lazy<DashMap<String, Regex, ARandomState>> =
8080
Lazy::new(Default::default);
8181

8282
if !REGEX_CACHE.contains_key(pattern) {

‎crates/swc_ecma_lints/src/rules/no_param_reassign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use dashmap::DashMap;
22
use regex::Regex;
33
use serde::{Deserialize, Serialize};
44
use swc_common::{
5-
collections::{AHashMap, AHashSet},
5+
collections::{AHashMap, AHashSet, ARandomState},
66
errors::HANDLER,
77
sync::Lazy,
88
Span,
@@ -121,7 +121,7 @@ impl NoParamReassign {
121121
}
122122

123123
if let Some(ignore_names_patterns) = &self.ignore_names_patterns {
124-
static REGEX_CACHE: Lazy<DashMap<String, Regex, ahash::RandomState>> =
124+
static REGEX_CACHE: Lazy<DashMap<String, Regex, ARandomState>> =
125125
Lazy::new(Default::default);
126126

127127
let sym = &*ident.sym;

‎crates/swc_ecma_loader/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ node = ["normpath", "serde_json", "dashmap", "once_cell", "path-clean"]
2525
tsc = ["dashmap", "once_cell", "swc_cached"]
2626

2727
[dependencies]
28-
ahash = "0.8.3"
2928
anyhow = "1.0.71"
3029
dashmap = { version = "5.4.0", optional = true }
3130
lru = { version = "0.10.0", optional = true }

‎crates/swc_ecma_loader/src/resolvers/node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use path_clean::PathClean;
1818
use pathdiff::diff_paths;
1919
use serde::Deserialize;
2020
use swc_common::{
21-
collections::{AHashMap, AHashSet},
21+
collections::{AHashMap, AHashSet, ARandomState},
2222
FileName,
2323
};
2424
use tracing::{debug, trace, Level};
@@ -33,7 +33,7 @@ static PACKAGE: &str = "package.json";
3333
/// directory containing the package.json file which is important
3434
/// to ensure we only apply these `browser` rules to modules in
3535
/// the owning package.
36-
static BROWSER_CACHE: Lazy<DashMap<PathBuf, BrowserCache, ahash::RandomState>> =
36+
static BROWSER_CACHE: Lazy<DashMap<PathBuf, BrowserCache, ARandomState>> =
3737
Lazy::new(Default::default);
3838

3939
#[derive(Debug, Default)]

‎crates/swc_ecma_minifier/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ serde-impl = []
3333
trace-ast = []
3434

3535
[dependencies]
36-
ahash = "0.8.3"
3736
arrayvec = "0.7.2"
3837
backtrace = { version = "0.3.61", optional = true }
3938
indexmap = "1.9.3"

‎crates/swc_ecma_minifier/src/program_data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use indexmap::IndexSet;
77
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
88
use swc_atoms::JsWord;
99
use swc_common::{
10-
collections::{AHashMap, AHashSet},
10+
collections::{AHashMap, AHashSet, ARandomState},
1111
SyntaxContext,
1212
};
1313
use swc_ecma_ast::*;
@@ -38,7 +38,7 @@ pub(crate) struct ProgramData {
3838

3939
pub(crate) scopes: FxHashMap<SyntaxContext, ScopeData>,
4040

41-
initialized_vars: IndexSet<Id, ahash::RandomState>,
41+
initialized_vars: IndexSet<Id, ARandomState>,
4242
}
4343

4444
#[derive(Debug, Default, Clone)]

‎crates/swc_ecma_preset_env/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ default = ["serde-impl"]
1616
serde-impl = ["serde"]
1717

1818
[dependencies]
19-
ahash = "0.8.3"
2019
anyhow = "1"
2120
dashmap = "5.4.0"
2221
indexmap = "1.9.3"

‎crates/swc_ecma_preset_env/src/corejs2/entry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use indexmap::IndexSet;
22
use preset_env_base::{version::should_enable, Versions};
33
use swc_atoms::js_word;
4-
use swc_common::DUMMY_SP;
4+
use swc_common::{collections::ARandomState, DUMMY_SP};
55
use swc_ecma_ast::*;
66
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
77

@@ -11,7 +11,7 @@ use super::builtin::BUILTINS;
1111
pub struct Entry {
1212
is_any_target: bool,
1313
target: Versions,
14-
pub imports: IndexSet<&'static str, ahash::RandomState>,
14+
pub imports: IndexSet<&'static str, ARandomState>,
1515
}
1616

1717
impl Entry {

‎crates/swc_ecma_preset_env/src/corejs2/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use indexmap::IndexSet;
22
use preset_env_base::{version::should_enable, Versions};
33
use swc_atoms::{js_word, JsWord};
4-
use swc_common::DUMMY_SP;
4+
use swc_common::{collections::ARandomState, DUMMY_SP};
55
use swc_ecma_ast::*;
66
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
77

@@ -19,7 +19,7 @@ mod entry;
1919
pub(crate) struct UsageVisitor {
2020
is_any_target: bool,
2121
target: Versions,
22-
pub required: IndexSet<&'static str, ahash::RandomState>,
22+
pub required: IndexSet<&'static str, ARandomState>,
2323
}
2424

2525
impl UsageVisitor {

‎crates/swc_ecma_preset_env/src/corejs3/entry.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use preset_env_base::{
55
Versions,
66
};
77
use swc_atoms::js_word;
8-
use swc_common::{collections::AHashMap, DUMMY_SP};
8+
use swc_common::{
9+
collections::{AHashMap, ARandomState},
10+
DUMMY_SP,
11+
};
912
use swc_ecma_ast::*;
1013
use swc_ecma_visit::VisitMut;
1114

@@ -33,7 +36,7 @@ pub struct Entry {
3336
is_any_target: bool,
3437
target: Versions,
3538
corejs_version: Version,
36-
pub imports: IndexSet<&'static str, ahash::RandomState>,
39+
pub imports: IndexSet<&'static str, ARandomState>,
3740
remove_regenerator: bool,
3841
}
3942

‎crates/swc_ecma_preset_env/src/corejs3/usage.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use indexmap::IndexSet;
22
use preset_env_base::version::{should_enable, Version};
33
use swc_atoms::{js_word, JsWord};
4-
use swc_common::DUMMY_SP;
4+
use swc_common::{collections::ARandomState, DUMMY_SP};
55
use swc_ecma_ast::*;
66
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
77

@@ -20,7 +20,7 @@ pub(crate) struct UsageVisitor {
2020
is_any_target: bool,
2121
target: Versions,
2222
corejs_version: Version,
23-
pub required: IndexSet<&'static str, ahash::RandomState>,
23+
pub required: IndexSet<&'static str, ARandomState>,
2424
}
2525

2626
impl UsageVisitor {

‎crates/swc_ecma_transforms_compat/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ concurrent = [
2020
]
2121

2222
[dependencies]
23-
ahash = "0.8.3"
2423
arrayvec = "0.7.2"
2524
indexmap = "1.9.3"
2625
is-macro = "0.3.0"

‎crates/swc_ecma_transforms_compat/src/es2015/block_scoping/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use std::mem::take;
22

3-
use ahash::AHashSet;
43
use indexmap::IndexMap;
54
use smallvec::SmallVec;
65
use swc_atoms::{js_word, JsWord};
76
use swc_common::{
8-
chain, collections::AHashMap, util::take::Take, Mark, Spanned, SyntaxContext, DUMMY_SP,
7+
chain,
8+
collections::{AHashMap, AHashSet},
9+
util::take::Take,
10+
Mark, Spanned, SyntaxContext, DUMMY_SP,
911
};
1012
use swc_ecma_ast::*;
1113
use swc_ecma_transforms_base::helper;
@@ -160,7 +162,7 @@ impl BlockScoping {
160162
has_return: false,
161163
has_yield: false,
162164
label: IndexMap::new(),
163-
inner_label: AHashSet::new(),
165+
inner_label: AHashSet::default(),
164166
mutated,
165167
in_switch_case: false,
166168
in_nested_loop: false,

‎crates/swc_ecma_transforms_compat/src/es2015/block_scoping/vars.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use indexmap::IndexMap;
22
use swc_atoms::JsWord;
3-
use swc_common::{collections::AHashMap, Mark, SyntaxContext};
3+
use swc_common::{
4+
collections::{AHashMap, ARandomState},
5+
Mark, SyntaxContext,
6+
};
47
use swc_ecma_ast::*;
58
use swc_ecma_transforms_base::scope::ScopeKind;
69
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
@@ -24,7 +27,7 @@ struct BlockScopedVars {
2427
struct Scope {
2528
kind: ScopeKind,
2629

27-
vars: IndexMap<Id, VarDeclKind, ahash::RandomState>,
30+
vars: IndexMap<Id, VarDeclKind, ARandomState>,
2831
usages: Vec<Id>,
2932

3033
children: Vec<Scope>,
@@ -34,7 +37,7 @@ struct Scope {
3437
struct ParentScope<'a> {
3538
parent: Option<&'a ParentScope<'a>>,
3639

37-
vars: &'a IndexMap<Id, VarDeclKind, ahash::RandomState>,
40+
vars: &'a IndexMap<Id, VarDeclKind, ARandomState>,
3841
}
3942

4043
#[swc_trace]

‎crates/swc_ecma_transforms_compat/src/es2015/classes/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::iter;
22

33
use serde::Deserialize;
4-
use swc_common::{comments::Comments, util::take::Take, BytePos, Mark, Span, Spanned, DUMMY_SP};
4+
use swc_common::{
5+
collections::ARandomState, comments::Comments, util::take::Take, BytePos, Mark, Span, Spanned,
6+
DUMMY_SP,
7+
};
58
use swc_ecma_ast::*;
69
use swc_ecma_transforms_base::{helper, native::is_native, perf::Check};
710
use swc_ecma_transforms_classes::super_field::SuperFieldAccessFolder;
@@ -42,7 +45,7 @@ where
4245
})
4346
}
4447

45-
type IndexMap<K, V> = indexmap::IndexMap<K, V, ahash::RandomState>;
48+
type IndexMap<K, V> = indexmap::IndexMap<K, V, ARandomState>;
4649

4750
/// `@babel/plugin-transform-classes`
4851
///

‎crates/swc_ecma_transforms_module/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ bench = false
1414

1515
[dependencies]
1616
Inflector = "0.11.4"
17-
ahash = "0.8.3"
1817
anyhow = "1.0.71"
1918
bitflags = "2.3.2"
2019
indexmap = "1.9.3"

‎crates/swc_ecma_transforms_optimization/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ concurrent = [
2222
debug = []
2323

2424
[dependencies]
25-
ahash = "0.8.3"
2625
dashmap = "5.4.0"
2726
indexmap = "1.9.3"
2827
once_cell = "1.18.0"

‎crates/swc_ecma_transforms_optimization/src/const_modules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
88
use rustc_hash::FxHashMap;
99
use swc_atoms::{js_word, JsWord};
1010
use swc_common::{
11+
collections::ARandomState,
1112
errors::HANDLER,
1213
sync::Lrc,
1314
util::{move_map::MoveMap, take::Take},
@@ -43,8 +44,7 @@ pub fn const_modules(
4344
}
4445

4546
fn parse_option(cm: &SourceMap, name: &str, src: String) -> Arc<Expr> {
46-
static CACHE: Lazy<DashMap<String, Arc<Expr>, ahash::RandomState>> =
47-
Lazy::new(DashMap::default);
47+
static CACHE: Lazy<DashMap<String, Arc<Expr>, ARandomState>> = Lazy::new(DashMap::default);
4848

4949
let fm = cm.new_source_file(FileName::Custom(format!("<const-module-{}.js>", name)), src);
5050
if let Some(expr) = CACHE.get(&**fm.src) {

‎crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use petgraph::{algo::tarjan_scc, Direction::Incoming};
55
use rustc_hash::FxHashSet;
66
use swc_atoms::{js_word, JsWord};
77
use swc_common::{
8-
collections::{AHashMap, AHashSet},
8+
collections::{AHashMap, AHashSet, ARandomState},
99
pass::{CompilerPass, Repeated},
1010
util::take::Take,
1111
Mark, SyntaxContext, DUMMY_SP,
@@ -113,7 +113,7 @@ struct Data {
113113
/// Entrypoints.
114114
entries: FxHashSet<u32>,
115115

116-
graph_ix: IndexSet<Id, ahash::RandomState>,
116+
graph_ix: IndexSet<Id, ARandomState>,
117117
}
118118

119119
impl Data {

‎crates/swc_ecma_transforms_optimization/src/simplify/inlining/scope.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88

99
use indexmap::map::{Entry, IndexMap};
1010
use swc_atoms::js_word;
11-
use swc_common::collections::{AHashMap, AHashSet};
11+
use swc_common::collections::{AHashMap, AHashSet, ARandomState};
1212
use swc_ecma_ast::*;
1313
use swc_ecma_transforms_base::ext::ExprRefExt;
1414
use tracing::{span, Level};
@@ -243,7 +243,7 @@ pub(super) struct Scope<'a> {
243243
pub kind: ScopeKind,
244244

245245
inline_barriers: RefCell<VecDeque<usize>>,
246-
bindings: IndexMap<Id, VarInfo, ahash::RandomState>,
246+
bindings: IndexMap<Id, VarInfo, ARandomState>,
247247
unresolved_usages: AHashSet<Id>,
248248

249249
/// Simple optimization. We don't need complex scope analysis.

‎crates/swc_ecma_transforms_react/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ default = ["serde-impl"]
1818
serde-impl = ["serde"]
1919

2020
[dependencies]
21-
ahash = "0.8.3"
2221
base64 = "0.13.0"
2322
dashmap = "5.4.0"
2423
indexmap = "1.9.3"

‎crates/swc_ecma_usage_analyzer/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ concurrent = ["swc_common/concurrent", "indexmap/rayon"]
2222
trace-ast = []
2323

2424
[dependencies]
25-
ahash = "0.8.3"
2625
indexmap = "1.9.3"
2726
rustc-hash = "1.1.0"
2827
tracing = "0.1.37"

‎crates/swc_graph_analyzer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ version = "0.20.22"
1212
bench = false
1313

1414
[dependencies]
15-
ahash = "0.8.3"
1615
auto_impl = "1.1.0"
1716
petgraph = "0.6.0"
17+
swc_common = {version = "0.31.18", path = "../swc_common/"}
1818
swc_fast_graph = {version = "0.19.19", path = "../swc_fast_graph/"}
1919
tracing = "0.1.37"
2020

‎crates/swc_graph_analyzer/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{fmt::Debug, hash::Hash, marker::PhantomData};
22

3-
use ahash::AHashSet;
43
use auto_impl::auto_impl;
4+
use swc_common::collections::AHashSet;
55
use swc_fast_graph::digraph::FastDiGraphMap;
66

77
#[auto_impl(&, Box, Rc, Arc)]

‎crates/swc_node_comments/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ version = "0.18.19"
1515
bench = false
1616

1717
[dependencies]
18-
ahash = "0.8.3"
1918
dashmap = "5.4.0"
2019

2120
swc_atoms = { version = "0.5.8", path = "../swc_atoms" }

‎crates/swc_node_comments/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use std::sync::Arc;
55
use dashmap::DashMap;
66
use swc_atoms::atom;
77
use swc_common::{
8+
collections::ARandomState,
89
comments::{Comment, CommentKind, Comments},
910
BytePos, DUMMY_SP,
1011
};
1112

12-
type CommentMap = Arc<DashMap<BytePos, Vec<Comment>, ahash::RandomState>>;
13+
type CommentMap = Arc<DashMap<BytePos, Vec<Comment>, ARandomState>>;
1314

1415
/// Multi-threaded implementation of [Comments]
1516
#[derive(Clone, Default)]

1 commit comments

Comments
 (1)

github-actions[bot] commented on Aug 16, 2023

@github-actions[bot]

Benchmark

Benchmark suite Current: b43e38d Previous: 8b809db Ratio
es/full/bugs-1 288172 ns/iter (± 5458) 288636 ns/iter (± 6993) 1.00
es/full/minify/libraries/antd 1359085106 ns/iter (± 31967358) 1322030778 ns/iter (± 19388878) 1.03
es/full/minify/libraries/d3 287914427 ns/iter (± 5911039) 272123651 ns/iter (± 3165031) 1.06
es/full/minify/libraries/echarts 1103774738 ns/iter (± 23162266) 1057658124 ns/iter (± 8826843) 1.04
es/full/minify/libraries/jquery 85720262 ns/iter (± 205767) 84981244 ns/iter (± 197210) 1.01
es/full/minify/libraries/lodash 99670875 ns/iter (± 647857) 98420258 ns/iter (± 281812) 1.01
es/full/minify/libraries/moment 50724162 ns/iter (± 415253) 49920560 ns/iter (± 458400) 1.02
es/full/minify/libraries/react 18075434 ns/iter (± 54002) 18018448 ns/iter (± 52485) 1.00
es/full/minify/libraries/terser 222746257 ns/iter (± 2644116) 220191443 ns/iter (± 1506787) 1.01
es/full/minify/libraries/three 404465543 ns/iter (± 9165189) 385568237 ns/iter (± 1655649) 1.05
es/full/minify/libraries/typescript 2731636000 ns/iter (± 56436850) 2676292546 ns/iter (± 14166789) 1.02
es/full/minify/libraries/victory 595382442 ns/iter (± 8407851) 573290633 ns/iter (± 6035343) 1.04
es/full/minify/libraries/vue 122254187 ns/iter (± 1421315) 120742143 ns/iter (± 295304) 1.01
es/full/codegen/es3 33937 ns/iter (± 66) 35003 ns/iter (± 115) 0.97
es/full/codegen/es5 33854 ns/iter (± 50) 35010 ns/iter (± 53) 0.97
es/full/codegen/es2015 33930 ns/iter (± 93) 35016 ns/iter (± 142) 0.97
es/full/codegen/es2016 34102 ns/iter (± 101) 34991 ns/iter (± 103) 0.97
es/full/codegen/es2017 33916 ns/iter (± 64) 35087 ns/iter (± 447) 0.97
es/full/codegen/es2018 33890 ns/iter (± 111) 35070 ns/iter (± 150) 0.97
es/full/codegen/es2019 33917 ns/iter (± 83) 35044 ns/iter (± 80) 0.97
es/full/codegen/es2020 33906 ns/iter (± 75) 35062 ns/iter (± 61) 0.97
es/full/all/es3 167593392 ns/iter (± 1257121) 169992626 ns/iter (± 1834897) 0.99
es/full/all/es5 161173497 ns/iter (± 1014677) 162315773 ns/iter (± 1087248) 0.99
es/full/all/es2015 120634431 ns/iter (± 637712) 120824552 ns/iter (± 558375) 1.00
es/full/all/es2016 118907811 ns/iter (± 1121341) 119189941 ns/iter (± 527764) 1.00
es/full/all/es2017 118753801 ns/iter (± 1270865) 119032321 ns/iter (± 827929) 1.00
es/full/all/es2018 116426042 ns/iter (± 765582) 116565943 ns/iter (± 450884) 1.00
es/full/all/es2019 115955266 ns/iter (± 626143) 115752579 ns/iter (± 392763) 1.00
es/full/all/es2020 111429934 ns/iter (± 610521) 111294239 ns/iter (± 1806121) 1.00
es/full/parser 498062 ns/iter (± 4834) 484679 ns/iter (± 3256) 1.03
es/full/base/fixer 18054 ns/iter (± 86) 17585 ns/iter (± 47) 1.03
es/full/base/resolver_and_hygiene 80596 ns/iter (± 96) 79587 ns/iter (± 748) 1.01
serialization of serde 293 ns/iter (± 3) 291 ns/iter (± 2) 1.01
css/minify/libraries/bootstrap 28361121 ns/iter (± 338762) 30015443 ns/iter (± 107447) 0.94
css/visitor/compare/clone 1640267 ns/iter (± 5942) 1649228 ns/iter (± 24145) 0.99
css/visitor/compare/visit_mut_span 1778530 ns/iter (± 15348) 1766549 ns/iter (± 10265) 1.01
css/visitor/compare/visit_mut_span_panic 1828127 ns/iter (± 7277) 1852369 ns/iter (± 23069) 0.99
css/visitor/compare/fold_span 2600207 ns/iter (± 17654) 2566121 ns/iter (± 10811) 1.01
css/visitor/compare/fold_span_panic 2744192 ns/iter (± 17834) 2741722 ns/iter (± 9991) 1.00
css/lexer/bootstrap_5_1_3 4550146 ns/iter (± 9188) 4447062 ns/iter (± 34180) 1.02
css/lexer/foundation_6_7_4 3844039 ns/iter (± 3836) 3746492 ns/iter (± 1912) 1.03
css/lexer/tailwind_3_1_1 728986 ns/iter (± 9987) 711633 ns/iter (± 1365) 1.02
css/parser/bootstrap_5_1_3 19623078 ns/iter (± 64561) 19511856 ns/iter (± 241040) 1.01
css/parser/foundation_6_7_4 15590759 ns/iter (± 33511) 15686508 ns/iter (± 14446) 0.99
css/parser/tailwind_3_1_1 2975402 ns/iter (± 6077) 3036624 ns/iter (± 2131) 0.98
es/codegen/colors 737912 ns/iter (± 404036) 740022 ns/iter (± 404481) 1.00
es/codegen/large 2890718 ns/iter (± 1527228) 2904806 ns/iter (± 1530129) 1.00
es/codegen/with-parser/colors 45590 ns/iter (± 163) 46116 ns/iter (± 207) 0.99
es/codegen/with-parser/large 495612 ns/iter (± 1249) 486899 ns/iter (± 683) 1.02
es/minify/libraries/antd 1185766472 ns/iter (± 22078083) 1173469536 ns/iter (± 17104191) 1.01
es/minify/libraries/d3 242864554 ns/iter (± 1510392) 240901922 ns/iter (± 608773) 1.01
es/minify/libraries/echarts 929200719 ns/iter (± 9097093) 916346139 ns/iter (± 5032112) 1.01
es/minify/libraries/jquery 73929269 ns/iter (± 264138) 73793547 ns/iter (± 115659) 1.00
es/minify/libraries/lodash 88179159 ns/iter (± 382769) 87849194 ns/iter (± 201204) 1.00
es/minify/libraries/moment 43443787 ns/iter (± 113105) 43506408 ns/iter (± 63847) 1.00
es/minify/libraries/react 16007026 ns/iter (± 37853) 16013943 ns/iter (± 46848) 1.00
es/minify/libraries/terser 188862239 ns/iter (± 1242346) 189022877 ns/iter (± 1334070) 1.00
es/minify/libraries/three 326404511 ns/iter (± 2498438) 335080964 ns/iter (± 9147349) 0.97
es/minify/libraries/typescript 2314216767 ns/iter (± 12655617) 2338615432 ns/iter (± 24290309) 0.99
es/minify/libraries/victory 488936511 ns/iter (± 4844647) 519509998 ns/iter (± 12089772) 0.94
es/minify/libraries/vue 107353324 ns/iter (± 464779) 110400159 ns/iter (± 1661655) 0.97
es/visitor/compare/clone 1921042 ns/iter (± 4115) 1940648 ns/iter (± 4811) 0.99
es/visitor/compare/visit_mut_span 2263549 ns/iter (± 7601) 2280226 ns/iter (± 4693) 0.99
es/visitor/compare/visit_mut_span_panic 2315951 ns/iter (± 4434) 2329730 ns/iter (± 24559) 0.99
es/visitor/compare/fold_span 3349872 ns/iter (± 6983) 3540043 ns/iter (± 59565) 0.95
es/visitor/compare/fold_span_panic 3419833 ns/iter (± 6002) 3655167 ns/iter (± 29877) 0.94
es/lexer/colors 13874 ns/iter (± 21) 13129 ns/iter (± 29) 1.06
es/lexer/angular 6354353 ns/iter (± 4301) 6105410 ns/iter (± 5589) 1.04
es/lexer/backbone 845056 ns/iter (± 1797) 793894 ns/iter (± 1473) 1.06
es/lexer/jquery 4696587 ns/iter (± 11063) 4479731 ns/iter (± 4277) 1.05
es/lexer/jquery mobile 7279898 ns/iter (± 61688) 6860056 ns/iter (± 4403) 1.06
es/lexer/mootools 3753072 ns/iter (± 31519) 3557281 ns/iter (± 3705) 1.06
es/lexer/underscore 695762 ns/iter (± 320) 666279 ns/iter (± 2174) 1.04
es/lexer/three 22428180 ns/iter (± 22606) 21509846 ns/iter (± 24279) 1.04
es/lexer/yui 4008528 ns/iter (± 4017) 3831564 ns/iter (± 2587) 1.05
es/parser/colors 27052 ns/iter (± 40) 28069 ns/iter (± 58) 0.96
es/parser/angular 13506143 ns/iter (± 111740) 13822530 ns/iter (± 84196) 0.98
es/parser/backbone 2005540 ns/iter (± 12842) 2034428 ns/iter (± 6384) 0.99
es/parser/jquery 10928574 ns/iter (± 59844) 11055371 ns/iter (± 46105) 0.99
es/parser/jquery mobile 16899596 ns/iter (± 111471) 16945610 ns/iter (± 75471) 1.00
es/parser/mootools 8409690 ns/iter (± 41660) 8533870 ns/iter (± 20809) 0.99
es/parser/underscore 1735780 ns/iter (± 9573) 1747855 ns/iter (± 10316) 0.99
es/parser/three 48158395 ns/iter (± 671549) 48670826 ns/iter (± 452514) 0.99
es/parser/yui 8301964 ns/iter (± 25909) 8437201 ns/iter (± 35765) 0.98
es/preset-env/usage/builtin_type 136120 ns/iter (± 32812) 136603 ns/iter (± 32197) 1.00
es/preset-env/usage/property 16641 ns/iter (± 62) 16807 ns/iter (± 79) 0.99
es/resolver/typescript 89214416 ns/iter (± 1606142) 90213962 ns/iter (± 1454630) 0.99
es/fixer/typescript 64704572 ns/iter (± 1425851) 64924050 ns/iter (± 1561414) 1.00
es/hygiene/typescript 131929231 ns/iter (± 1401456) 132379934 ns/iter (± 1170358) 1.00
es/resolver_with_hygiene/typescript 248366770 ns/iter (± 1983348) 243486621 ns/iter (± 1507382) 1.02
es/visitor/base-perf/module_clone 60231 ns/iter (± 286) 60520 ns/iter (± 296) 1.00
es/visitor/base-perf/fold_empty 64008 ns/iter (± 249) 64118 ns/iter (± 158) 1.00
es/visitor/base-perf/fold_noop_impl_all 64048 ns/iter (± 211) 63876 ns/iter (± 753) 1.00
es/visitor/base-perf/fold_noop_impl_vec 64148 ns/iter (± 247) 64880 ns/iter (± 330) 0.99
es/visitor/base-perf/boxing_boxed_clone 58 ns/iter (± 0) 58 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed_clone 39 ns/iter (± 0) 40 ns/iter (± 0) 0.97
es/visitor/base-perf/boxing_boxed 108 ns/iter (± 0) 105 ns/iter (± 0) 1.03
es/visitor/base-perf/boxing_unboxed 77 ns/iter (± 0) 75 ns/iter (± 0) 1.03
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 2635 ns/iter (± 14) 2581 ns/iter (± 14) 1.02
es/base/parallel/resolver/typescript 4445464517 ns/iter (± 271132462) 4084810886 ns/iter (± 309075363) 1.09
es/base/parallel/hygiene/typescript 1448507641 ns/iter (± 19089554) 1462569620 ns/iter (± 12485381) 0.99
misc/visitors/time-complexity/time 5 133 ns/iter (± 0) 134 ns/iter (± 7) 0.99
misc/visitors/time-complexity/time 10 396 ns/iter (± 2) 379 ns/iter (± 0) 1.04
misc/visitors/time-complexity/time 15 676 ns/iter (± 4) 523 ns/iter (± 1) 1.29
misc/visitors/time-complexity/time 20 1064 ns/iter (± 3) 1019 ns/iter (± 2) 1.04
misc/visitors/time-complexity/time 40 3540 ns/iter (± 42) 3652 ns/iter (± 13) 0.97
misc/visitors/time-complexity/time 60 8783 ns/iter (± 10) 7402 ns/iter (± 27) 1.19
es/full-target/es2016 232559 ns/iter (± 939) 232238 ns/iter (± 532) 1.00
es/full-target/es2017 219460 ns/iter (± 514) 221214 ns/iter (± 836) 0.99
es/full-target/es2018 208045 ns/iter (± 1006) 208563 ns/iter (± 777) 1.00
es2020_nullish_coalescing 72004 ns/iter (± 275) 71803 ns/iter (± 177) 1.00
es2020_optional_chaining 83131 ns/iter (± 519) 80451 ns/iter (± 259) 1.03
es2022_class_properties 115978 ns/iter (± 244) 117186 ns/iter (± 486) 0.99
es2018_object_rest_spread 76723 ns/iter (± 308) 75503 ns/iter (± 236) 1.02
es2019_optional_catch_binding 65296 ns/iter (± 152) 66374 ns/iter (± 278) 0.98
es2017_async_to_generator 64814 ns/iter (± 155) 64871 ns/iter (± 155) 1.00
es2016_exponentiation 69324 ns/iter (± 224) 69481 ns/iter (± 189) 1.00
es2015_arrow 72095 ns/iter (± 211) 72750 ns/iter (± 317) 0.99
es2015_block_scoped_fn 69487 ns/iter (± 194) 69698 ns/iter (± 170) 1.00
es2015_block_scoping 120776 ns/iter (± 618) 123807 ns/iter (± 482) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.