diff --git a/Cargo.lock b/Cargo.lock index 457988c3104c..c4107e6da122 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1945,9 +1945,9 @@ dependencies = [ [[package]] name = "hstr" -version = "0.2.12" +version = "0.2.13" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "dae404c0c5d4e95d4858876ab02eecd6a196bb8caa42050dfa809938833fc412" +checksum = "1ddb0a5bb453eee36a8a2e1f08b7938ac9e2f62dc464007af7b328d551eca6b9" dependencies = [ "hashbrown 0.14.5", "new_debug_unreachable", diff --git a/Cargo.toml b/Cargo.toml index 174cccc5a4b2..7f038672b548 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,7 +78,7 @@ resolver = "2" glob = "0.3.0" hashbrown = "0.14.5" hex = "0.4.3" - hstr = "0.2.12" + hstr = "0.2.13" indexmap = "2.0.0" is-macro = "0.3.5" js-sys = "0.3.59" diff --git a/crates/swc_atoms/src/lib.rs b/crates/swc_atoms/src/lib.rs index 1ed9365a6ca1..6d018209a4b2 100644 --- a/crates/swc_atoms/src/lib.rs +++ b/crates/swc_atoms/src/lib.rs @@ -104,6 +104,13 @@ macro_rules! impl_from { }; } +impl From for Atom { + #[inline(always)] + fn from(s: hstr::Atom) -> Self { + Atom(s) + } +} + impl PartialEq for Atom { fn eq(&self, other: &str) -> bool { &**self == other @@ -174,7 +181,7 @@ impl<'de> serde::de::Deserialize<'de> for Atom { #[macro_export] macro_rules! atom { ($s:tt) => {{ - $crate::Atom::new($crate::hstr::atom!($s)) + $crate::Atom::from($crate::hstr::atom!($s)) }}; } @@ -182,7 +189,7 @@ macro_rules! atom { #[macro_export] macro_rules! lazy_atom { ($s:tt) => {{ - $crate::Atom::new($crate::hstr::atom!($s)) + $crate::Atom::from($crate::hstr::atom!($s)) }}; } diff --git a/crates/swc_ecma_minifier/src/compress/pure/mod.rs b/crates/swc_ecma_minifier/src/compress/pure/mod.rs index 3f32d05efaec..b8fa2923868a 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/mod.rs @@ -169,15 +169,16 @@ impl Pure<'_> { N: for<'aa> VisitMutWith> + Send + Sync, { let mut changed = false; - if !cfg!(target_arch = "wasm32") - && (!cfg!(feature = "debug") || !cfg!(debug_assertions)) - && nodes.len() >= *crate::HEAVY_TASK_PARALLELS - { + if !cfg!(target_arch = "wasm32") && (!cfg!(feature = "debug") || !cfg!(debug_assertions)) { #[cfg(feature = "concurrent")] { GLOBALS.with(|globals| { changed = nodes .par_iter_mut() + .with_min_len( + (*crate::HEAVY_TASK_PARALLELS) + * (f32::log2(self.ctx.par_depth as f32).floor() as usize), + ) .map(|node| { GLOBALS.set(globals, || { let mut v = Pure { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs index b4e1201b68ea..b3ec1a538216 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs @@ -3,7 +3,7 @@ use std::{borrow::Cow, sync::Arc}; use indexmap::IndexSet; use petgraph::{algo::tarjan_scc, Direction::Incoming}; use rustc_hash::FxHashSet; -use swc_atoms::JsWord; +use swc_atoms::{atom, JsWord}; use swc_common::{ collections::{AHashMap, AHashSet, ARandomState}, pass::{CompilerPass, Repeated}, @@ -127,9 +127,9 @@ impl Data { } /// Add an edge to dependency graph - fn add_dep_edge(&mut self, from: Id, to: Id, assign: bool) { - let from = self.node(&from); - let to = self.node(&to); + fn add_dep_edge(&mut self, from: &Id, to: &Id, assign: bool) { + let from = self.node(from); + let to = self.node(to); match self.graph.edge_weight_mut(from, to) { Some(info) => { @@ -311,7 +311,7 @@ impl Analyzer<'_> { /// Mark `id` as used fn add(&mut self, id: Id, assign: bool) { - if id.0 == "arguments" { + if id.0 == atom!("arguments") { self.scope.found_arguemnts = true; } @@ -335,8 +335,7 @@ impl Analyzer<'_> { while let Some(s) = scope { for component in &s.ast_path { - self.data - .add_dep_edge(component.clone(), id.clone(), assign) + self.data.add_dep_edge(component, &id, assign); } if s.kind == ScopeKind::Fn && !s.ast_path.is_empty() {