From 27896f4751e72c12eaadeb302848083df8e8e842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 19 Oct 2022 13:53:46 +0900 Subject: [PATCH] perf(es/transforms): Exclude old inlining pass (#6203) **Related issue:** - Closes https://github.com/swc-project/swc/issues/6194. --- crates/swc/benches/bugs.rs | 4 +-- .../{reassignment => .reassignment}/exec.js | 0 .../exec.js | 0 .../fixture/issues-2xxx/2108/output/index.js | 2 +- .../src/simplify/mod.rs | 1 - .../tests/simplify.rs | 25 ++++++++++++++++--- .../swc_html_parser/tests/html5lib_tests.rs | 3 +-- 7 files changed, 25 insertions(+), 10 deletions(-) rename crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/{reassignment => .reassignment}/exec.js (100%) rename crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/{set-only-getter => .set-only-getter}/exec.js (100%) diff --git a/crates/swc/benches/bugs.rs b/crates/swc/benches/bugs.rs index 68956b6cfe6..58e762d2099 100644 --- a/crates/swc/benches/bugs.rs +++ b/crates/swc/benches/bugs.rs @@ -2,7 +2,7 @@ extern crate swc_node_base; use std::{io::stderr, path::Path}; -use criterion::{criterion_group, criterion_main, Bencher, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion}; use swc::config::{Config, IsModule, Options}; use swc_common::{errors::Handler, sync::Lrc, FilePathMapping, SourceMap}; use swc_ecma_utils::swc_common::GLOBALS; @@ -37,7 +37,7 @@ fn bench_file(b: &mut Bencher, path: &Path) { .unwrap() }) }; - println!("{}", result.code); + black_box(result); }); } diff --git a/crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/exec.js b/crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/.reassignment/exec.js similarity index 100% rename from crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/exec.js rename to crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/.reassignment/exec.js diff --git a/crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/exec.js b/crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/.set-only-getter/exec.js similarity index 100% rename from crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/exec.js rename to crates/swc/tests/babel-exec/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/.set-only-getter/exec.js diff --git a/crates/swc/tests/fixture/issues-2xxx/2108/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2108/output/index.js index e76789d5fbc..41b5f926a25 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2108/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2108/output/index.js @@ -1,6 +1,6 @@ "use strict"; function foo() { - let arr; + let arr = []; arr = [ 1, 2, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs index 8f360046f31..3d45ee1089f 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs @@ -25,7 +25,6 @@ pub struct Config { pub fn simplifier(unresolved_mark: Mark, c: Config) -> impl RepeatedJsPass { Repeat::new(chain!( expr_simplifier(unresolved_mark, c.expr), - inlining::inlining(c.inlining), dead_branch_remover(unresolved_mark), dce::dce(c.dce, unresolved_mark) )) diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify.rs b/crates/swc_ecma_transforms_optimization/tests/simplify.rs index d899c3012e4..e3598569e08 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify.rs @@ -8,7 +8,9 @@ use swc_ecma_transforms_base::{helpers::inject_helpers, resolver}; use swc_ecma_transforms_compat::{es2015, es2016, es2017, es2018, es2022::class_properties, es3}; use swc_ecma_transforms_module::{common_js::common_js, import_analysis::import_analyzer}; use swc_ecma_transforms_optimization::simplify::{ - dce::dce, dead_branch_remover, expr_simplifier, inlining::inlining, simplifier, + dce::{self, dce}, + dead_branch_remover, expr_simplifier, + inlining::{self, inlining}, }; use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_testing::{test, test_transform}; @@ -23,7 +25,12 @@ fn test(src: &str, expected: &str) { chain!( resolver(unresolved_mark, top_level_mark, false), - simplifier(unresolved_mark, Default::default()) + Repeat::new(chain!( + expr_simplifier(unresolved_mark, Default::default()), + inlining::inlining(Default::default()), + dead_branch_remover(unresolved_mark), + dce::dce(Default::default(), unresolved_mark) + )), ) }, src, @@ -46,7 +53,12 @@ macro_rules! to { chain!( resolver(unresolved_mark, top_level_mark, false), - simplifier(unresolved_mark, Default::default()) + Repeat::new(chain!( + expr_simplifier(unresolved_mark, Default::default()), + inlining::inlining(Default::default()), + dead_branch_remover(unresolved_mark), + dce::dce(Default::default(), unresolved_mark) + )), ) }, $name, @@ -574,7 +586,12 @@ test!( resolver(unresolved_mark, top_level_mark, false), strip(top_level_mark), class_properties(Some(t.comments.clone()), Default::default()), - simplifier(unresolved_mark, Default::default()), + Repeat::new(chain!( + expr_simplifier(unresolved_mark, Default::default()), + inlining::inlining(Default::default()), + dead_branch_remover(unresolved_mark), + dce::dce(Default::default(), unresolved_mark) + )), es2018(Default::default()), es2017( Default::default(), diff --git a/crates/swc_html_parser/tests/html5lib_tests.rs b/crates/swc_html_parser/tests/html5lib_tests.rs index a5250fa50b3..c2078fc622d 100644 --- a/crates/swc_html_parser/tests/html5lib_tests.rs +++ b/crates/swc_html_parser/tests/html5lib_tests.rs @@ -799,10 +799,9 @@ fn html5lib_test_tree_construction(input: PathBuf) { || file_name.contains("svg_dat.5.fragment_tbody") || file_name.contains("svg_dat.6.fragment_tbody") || file_name.contains("svg_dat.7.fragment_tbody") + || file_name.contains("foreign-fragment_dat.3.fragment_svg_path") { errors.len() - 1 - } else if file_name.contains("foreign-fragment_dat.3.fragment_svg_path") { - errors.len() - 1 } else { errors.len() };