mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
perf(es/minifier): Cache the list of bindings for DCE (#5750)
This commit is contained in:
parent
e8dd50c12e
commit
8789184d44
@ -386,19 +386,19 @@ where
|
||||
if self.options.unused {
|
||||
let _timer = timer!("remove dead code");
|
||||
|
||||
let mut visitor = swc_ecma_transforms_optimization::simplify::dce::dce(
|
||||
swc_ecma_transforms_optimization::simplify::dce::Config {
|
||||
module_mark: None,
|
||||
top_level: self.options.top_level(),
|
||||
top_retain: self.options.top_retain.clone(),
|
||||
},
|
||||
self.marks.unresolved_mark,
|
||||
);
|
||||
|
||||
loop {
|
||||
#[cfg(feature = "debug")]
|
||||
let start = n.dump();
|
||||
|
||||
let mut visitor = swc_ecma_transforms_optimization::simplify::dce::dce(
|
||||
swc_ecma_transforms_optimization::simplify::dce::Config {
|
||||
module_mark: None,
|
||||
top_level: self.options.top_level(),
|
||||
top_retain: self.options.top_retain.clone(),
|
||||
},
|
||||
self.marks.unresolved_mark,
|
||||
);
|
||||
|
||||
n.apply(&mut visitor);
|
||||
|
||||
self.changed |= visitor.changed();
|
||||
@ -417,6 +417,8 @@ where
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
visitor.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,11 @@ pub fn dce(
|
||||
config,
|
||||
changed: false,
|
||||
pass: 0,
|
||||
data: Default::default(),
|
||||
in_block_stmt: false,
|
||||
in_fn: false,
|
||||
in_block_stmt: false,
|
||||
var_decl_kind: None,
|
||||
data: Default::default(),
|
||||
bindings: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -86,6 +87,8 @@ struct TreeShaker {
|
||||
var_decl_kind: Option<VarDeclKind>,
|
||||
|
||||
data: Arc<Data>,
|
||||
|
||||
bindings: Arc<AHashSet<Id>>,
|
||||
}
|
||||
|
||||
impl CompilerPass for TreeShaker {
|
||||
@ -96,9 +99,6 @@ impl CompilerPass for TreeShaker {
|
||||
|
||||
#[derive(Default)]
|
||||
struct Data {
|
||||
/// Bindings in the module.
|
||||
bindings: AHashSet<Id>,
|
||||
|
||||
used_names: AHashMap<Id, VarInfo>,
|
||||
|
||||
/// Variable usage graph
|
||||
@ -535,6 +535,7 @@ impl Parallel for TreeShaker {
|
||||
expr_ctx: self.expr_ctx.clone(),
|
||||
data: self.data.clone(),
|
||||
config: self.config.clone(),
|
||||
bindings: self.bindings.clone(),
|
||||
..*self
|
||||
}
|
||||
}
|
||||
@ -606,7 +607,7 @@ impl TreeShaker {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.data.bindings.contains(&name)
|
||||
self.bindings.contains(&name)
|
||||
&& self
|
||||
.data
|
||||
.used_names
|
||||
@ -795,8 +796,11 @@ impl VisitMut for TreeShaker {
|
||||
fn visit_mut_module(&mut self, m: &mut Module) {
|
||||
let _tracing = span!(Level::ERROR, "tree-shaker", pass = self.pass).entered();
|
||||
|
||||
if self.bindings.is_empty() {
|
||||
self.bindings = Arc::new(collect_decls(&*m))
|
||||
}
|
||||
|
||||
let mut data = Data {
|
||||
bindings: collect_decls(&*m),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@ -822,8 +826,11 @@ impl VisitMut for TreeShaker {
|
||||
fn visit_mut_script(&mut self, m: &mut Script) {
|
||||
let _tracing = span!(Level::ERROR, "tree-shaker", pass = self.pass).entered();
|
||||
|
||||
if self.bindings.is_empty() {
|
||||
self.bindings = Arc::new(collect_decls(&*m))
|
||||
}
|
||||
|
||||
let mut data = Data {
|
||||
bindings: collect_decls(&*m),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user