Skip to content

Commit

Permalink
refactor(es/minifier): Remove unnecessary code (#6575)
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Dec 5, 2022
1 parent 2379fc1 commit 586bfd5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/lib.rs
Expand Up @@ -171,7 +171,7 @@ pub fn optimize(
options.compress.as_ref(),
comments,
marks,
extra.unresolved_mark,
// extra.unresolved_mark,
));
debug_assert_valid(&n);
}
Expand Down
148 changes: 74 additions & 74 deletions crates/swc_ecma_minifier/src/metadata/mod.rs
@@ -1,6 +1,6 @@
use swc_common::{
comments::{Comment, CommentKind, Comments},
EqIgnoreSpan, Mark, Span, SyntaxContext,
EqIgnoreSpan, Span, SyntaxContext,
};
use swc_ecma_ast::*;
use swc_ecma_utils::find_pat_ids;
Expand All @@ -18,13 +18,13 @@ pub(crate) fn info_marker<'a>(
options: Option<&'a CompressOptions>,
comments: Option<&'a dyn Comments>,
marks: Marks,
unresolved_mark: Mark,
// unresolved_mark: Mark,
) -> impl 'a + VisitMut {
InfoMarker {
options,
comments,
marks,
unresolved_mark,
// unresolved_mark,
state: Default::default(),
}
}
Expand All @@ -40,7 +40,7 @@ struct InfoMarker<'a> {

comments: Option<&'a dyn Comments>,
marks: Marks,
unresolved_mark: Mark,
// unresolved_mark: Mark,
state: State,
}

Expand Down Expand Up @@ -178,12 +178,12 @@ impl VisitMut for InfoMarker<'_> {
)
})
{
if is_standalone(&mut n.function, self.unresolved_mark) {
// self.state.is_bundle = true;
// if is_standalone(&mut n.function, self.unresolved_mark) {
// // self.state.is_bundle = true;

// n.function.span =
// n.function.span.apply_mark(self.marks.standalone);
}
// // n.function.span =
// // n.function.span.apply_mark(self.marks.standalone);
// }
}
}

Expand Down Expand Up @@ -267,71 +267,71 @@ impl Visit for TopLevelBindingCollector {
}
}

fn is_standalone<N>(n: &mut N, unresolved_mark: Mark) -> bool
where
N: VisitMutWith<IdentCollector>,
{
let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark);

let bindings = {
let mut v = IdentCollector {
ids: Default::default(),
for_binding: true,
is_pat_decl: false,
};
n.visit_mut_with(&mut v);
v.ids
};

let used = {
let mut v = IdentCollector {
ids: Default::default(),
for_binding: false,
is_pat_decl: false,
};
n.visit_mut_with(&mut v);
v.ids
};

for used_id in &used {
if used_id.0.starts_with("__WEBPACK_EXTERNAL_MODULE_") {
continue;
}

match &*used_id.0 {
"__webpack_require__" | "exports" => continue,
_ => {}
}

if used_id.1 == unresolved_ctxt {
// if cfg!(feature = "debug") {
// debug!("bundle: Ignoring {}{:?} (top level)", used_id.0,
// used_id.1); }
continue;
}

if bindings.contains(used_id) {
// if cfg!(feature = "debug") {
// debug!(
// "bundle: Ignoring {}{:?} (local to fn)",
// used_id.0,
// used_id.1
// );
// }
continue;
}

trace_op!(
"bundle: Due to {}{:?}, it's not a bundle",
used_id.0,
used_id.1
);

return false;
}

true
}
// fn is_standalone<N>(n: &mut N, unresolved_mark: Mark) -> bool
// where
// N: VisitMutWith<IdentCollector>,
// {
// let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark);

// let bindings = {
// let mut v = IdentCollector {
// ids: Default::default(),
// for_binding: true,
// is_pat_decl: false,
// };
// n.visit_mut_with(&mut v);
// v.ids
// };

// let used = {
// let mut v = IdentCollector {
// ids: Default::default(),
// for_binding: false,
// is_pat_decl: false,
// };
// n.visit_mut_with(&mut v);
// v.ids
// };

// for used_id in &used {
// if used_id.0.starts_with("__WEBPACK_EXTERNAL_MODULE_") {
// continue;
// }

// match &*used_id.0 {
// "__webpack_require__" | "exports" => continue,
// _ => {}
// }

// if used_id.1 == unresolved_ctxt {
// // if cfg!(feature = "debug") {
// // debug!("bundle: Ignoring {}{:?} (top level)", used_id.0,
// // used_id.1); }
// continue;
// }

// if bindings.contains(used_id) {
// // if cfg!(feature = "debug") {
// // debug!(
// // "bundle: Ignoring {}{:?} (local to fn)",
// // used_id.0,
// // used_id.1
// // );
// // }
// continue;
// }

// trace_op!(
// "bundle: Due to {}{:?}, it's not a bundle",
// used_id.0,
// used_id.1
// );

// return false;
// }

// true
// }

struct IdentCollector {
ids: Vec<Id>,
Expand Down

1 comment on commit 586bfd5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 586bfd5 Previous: a203fdb Ratio
es/full/bugs-1 350100 ns/iter (± 45789) 433858 ns/iter (± 60049) 0.81
es/full/minify/libraries/antd 2079368547 ns/iter (± 56382394) 2421609627 ns/iter (± 69302733) 0.86
es/full/minify/libraries/d3 452273945 ns/iter (± 13399812) 471887492 ns/iter (± 17014566) 0.96
es/full/minify/libraries/echarts 1925032414 ns/iter (± 136213967) 2117942431 ns/iter (± 71712587) 0.91
es/full/minify/libraries/jquery 138793302 ns/iter (± 16550415) 132923529 ns/iter (± 6559938) 1.04
es/full/minify/libraries/lodash 161781225 ns/iter (± 9311455) 152517116 ns/iter (± 5581911) 1.06
es/full/minify/libraries/moment 80058081 ns/iter (± 7019018) 84859642 ns/iter (± 52635634) 0.94
es/full/minify/libraries/react 24731757 ns/iter (± 1327717) 28651895 ns/iter (± 15209523) 0.86
es/full/minify/libraries/terser 380187969 ns/iter (± 23873811) 463019636 ns/iter (± 33428381) 0.82
es/full/minify/libraries/three 668744489 ns/iter (± 29634046) 736593634 ns/iter (± 66658898) 0.91
es/full/minify/libraries/typescript 4079520728 ns/iter (± 135939358) 4838105034 ns/iter (± 148445746) 0.84
es/full/minify/libraries/victory 971799374 ns/iter (± 85780814) 1112553848 ns/iter (± 83094318) 0.87
es/full/minify/libraries/vue 204497167 ns/iter (± 13635709) 215182264 ns/iter (± 24983236) 0.95
es/full/codegen/es3 35216 ns/iter (± 4610) 41999 ns/iter (± 886) 0.84
es/full/codegen/es5 34559 ns/iter (± 3108) 41891 ns/iter (± 2310) 0.82
es/full/codegen/es2015 34962 ns/iter (± 9023) 41479 ns/iter (± 2752) 0.84
es/full/codegen/es2016 35475 ns/iter (± 1608) 41953 ns/iter (± 5247) 0.85
es/full/codegen/es2017 35138 ns/iter (± 1558) 41691 ns/iter (± 3435) 0.84
es/full/codegen/es2018 34240 ns/iter (± 788) 43614 ns/iter (± 25098) 0.79
es/full/codegen/es2019 34225 ns/iter (± 1433) 41370 ns/iter (± 4333) 0.83
es/full/codegen/es2020 34298 ns/iter (± 1822) 42106 ns/iter (± 6950) 0.81
es/full/all/es3 191446317 ns/iter (± 25438241) 237538178 ns/iter (± 28711261) 0.81
es/full/all/es5 183373108 ns/iter (± 9189378) 225625443 ns/iter (± 17751187) 0.81
es/full/all/es2015 165586574 ns/iter (± 25538818) 179765309 ns/iter (± 17404803) 0.92
es/full/all/es2016 162010049 ns/iter (± 20415451) 182401069 ns/iter (± 15335932) 0.89
es/full/all/es2017 147239744 ns/iter (± 11160821) 177936455 ns/iter (± 15811367) 0.83
es/full/all/es2018 156883716 ns/iter (± 14331707) 175847881 ns/iter (± 19239088) 0.89
es/full/all/es2019 143742018 ns/iter (± 9816889) 175094541 ns/iter (± 17610050) 0.82
es/full/all/es2020 143493057 ns/iter (± 14207730) 168017276 ns/iter (± 15066806) 0.85
es/full/parser 719063 ns/iter (± 78550) 873718 ns/iter (± 35587) 0.82
es/full/base/fixer 26510 ns/iter (± 1024) 32642 ns/iter (± 1935) 0.81
es/full/base/resolver_and_hygiene 93078 ns/iter (± 6110) 117221 ns/iter (± 3824) 0.79
serialization of ast node 211 ns/iter (± 5) 252 ns/iter (± 13) 0.84
serialization of serde 234 ns/iter (± 7) 266 ns/iter (± 20) 0.88

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

Please sign in to comment.