mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
perf(es/minifier): Use fxhash for integers (#3984)
Description: - `Id` is treated as integer, as `JsWord` and `SyntaxContext` are both integer.
This commit is contained in:
parent
c6ddb5fcf5
commit
67e615421f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3283,6 +3283,7 @@ dependencies = [
|
||||
"rayon",
|
||||
"regex",
|
||||
"retain_mut",
|
||||
"rustc-hash",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"swc_atoms",
|
||||
|
@ -26,6 +26,7 @@ pretty_assertions = {version = "1.1", optional = true}
|
||||
rayon = "1.5.1"
|
||||
regex = "1.5.3"
|
||||
retain_mut = "0.1.2"
|
||||
rustc-hash = "1.1.0"
|
||||
serde = {version = "1.0.118", features = ["derive"]}
|
||||
serde_json = "1.0.61"
|
||||
swc_atoms = {version = "0.2", path = "../swc_atoms"}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use rustc_hash::FxHashSet;
|
||||
use swc_atoms::JsWord;
|
||||
use swc_common::collections::{AHashMap, AHashSet};
|
||||
use swc_common::collections::AHashMap;
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_utils::{ident::IdentLike, Id};
|
||||
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
|
||||
@ -21,7 +22,7 @@ impl Analyzer {
|
||||
pub(super) fn into_rename_map(
|
||||
mut self,
|
||||
freq: &CharFreqInfo,
|
||||
preserved: &AHashSet<Id>,
|
||||
preserved: &FxHashSet<Id>,
|
||||
) -> AHashMap<Id, JsWord> {
|
||||
let mut map = RenameMap::default();
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
use rustc_hash::FxHashSet;
|
||||
use swc_atoms::{js_word, JsWord};
|
||||
use swc_common::{collections::AHashSet, util::take::Take};
|
||||
use swc_common::util::take::Take;
|
||||
use swc_ecma_utils::Id;
|
||||
|
||||
use crate::pass::{compute_char_freq::CharFreqInfo, mangle_names::rename_map::RenameMap};
|
||||
@ -13,11 +14,7 @@ pub(crate) struct Scope {
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ScopeData {
|
||||
// decls: AHashSet<Id>,
|
||||
|
||||
// /// Usages in current scope.
|
||||
// usages: AHashSet<Id>,
|
||||
all: AHashSet<Id>,
|
||||
all: FxHashSet<Id>,
|
||||
|
||||
queue: Vec<(Id, u32)>,
|
||||
}
|
||||
@ -56,8 +53,8 @@ impl Scope {
|
||||
&mut self,
|
||||
f: &CharFreqInfo,
|
||||
to: &mut RenameMap,
|
||||
preserved: &AHashSet<Id>,
|
||||
preserved_symbols: &AHashSet<JsWord>,
|
||||
preserved: &FxHashSet<Id>,
|
||||
preserved_symbols: &FxHashSet<JsWord>,
|
||||
) {
|
||||
let mut n = 0;
|
||||
let mut queue = self.data.queue.take();
|
||||
|
@ -1,11 +1,11 @@
|
||||
use swc_common::collections::AHashSet;
|
||||
use rustc_hash::FxHashSet;
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_utils::{find_ids, ident::IdentLike, Id};
|
||||
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
|
||||
|
||||
use crate::option::MangleOptions;
|
||||
|
||||
pub(super) fn idents_to_preserve<N>(options: MangleOptions, n: &N) -> AHashSet<Id>
|
||||
pub(super) fn idents_to_preserve<N>(options: MangleOptions, n: &N) -> FxHashSet<Id>
|
||||
where
|
||||
N: VisitWith<Preserver>,
|
||||
{
|
||||
@ -20,7 +20,7 @@ where
|
||||
}
|
||||
pub(super) struct Preserver {
|
||||
options: MangleOptions,
|
||||
preserved: AHashSet<Id>,
|
||||
preserved: FxHashSet<Id>,
|
||||
should_preserve: bool,
|
||||
in_top_level: bool,
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use rustc_hash::FxHashMap;
|
||||
use swc_atoms::JsWord;
|
||||
use swc_common::collections::AHashMap;
|
||||
use swc_ecma_ast::Id;
|
||||
@ -5,7 +6,7 @@ use swc_ecma_ast::Id;
|
||||
#[derive(Default)]
|
||||
pub(super) struct RenameMap {
|
||||
map: AHashMap<Id, JsWord>,
|
||||
rev: AHashMap<JsWord, Vec<Id>>,
|
||||
rev: FxHashMap<JsWord, Vec<Id>>,
|
||||
}
|
||||
|
||||
impl RenameMap {
|
||||
|
Loading…
Reference in New Issue
Block a user