Skip to content

Commit

Permalink
fix(es): Improve performance (#1411)
Browse files Browse the repository at this point in the history
swc_ecma_ast:
 - Add `BindingIdent`.
 - Reduce size of `Ident`.
  • Loading branch information
kdy1 authored Feb 19, 2021
1 parent 0be20ff commit eaeffab
Show file tree
Hide file tree
Showing 4,061 changed files with 74,438 additions and 176,246 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
name: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
crate:
- ast_node
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.5.0"
version = "0.6.0"

[lib]
name = "swc"
Expand All @@ -27,21 +27,21 @@ serde_json = "1"
sourcemap = "6"
swc_atoms = {version = "0.2", path = "./atoms"}
swc_common = {version = "0.10", path = "./common", features = ["sourcemap", "concurrent"]}
swc_ecma_ast = {version = "0.38.0", path = "./ecmascript/ast"}
swc_ecma_codegen = {version = "0.45.0", path = "./ecmascript/codegen"}
swc_ecma_ext_transforms = {version = "0.4.0", path = "./ecmascript/ext-transforms"}
swc_ecma_parser = {version = "0.47.0", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.6.0", path = "./ecmascript/preset_env"}
swc_ecma_transforms = {version = "0.36.0", path = "./ecmascript/transforms", features = [
swc_ecma_ast = {version = "0.39.0", path = "./ecmascript/ast"}
swc_ecma_codegen = {version = "0.46.0", path = "./ecmascript/codegen"}
swc_ecma_ext_transforms = {version = "0.5.0", path = "./ecmascript/ext-transforms"}
swc_ecma_parser = {version = "0.48.0", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.7.0", path = "./ecmascript/preset_env"}
swc_ecma_transforms = {version = "0.37.0", path = "./ecmascript/transforms", features = [
"compat",
"module",
"optimization",
"proposal",
"react",
"typescript",
]}
swc_ecma_utils = {version = "0.28.0", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.24.0", path = "./ecmascript/visit"}
swc_ecma_utils = {version = "0.29.0", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.25.0", path = "./ecmascript/visit"}
swc_visit = {version = "0.2", path = "./visit"}

[dev-dependencies]
Expand Down
16 changes: 8 additions & 8 deletions bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"]
license = "Apache-2.0/MIT"
name = "swc_bundler"
repository = "https://github.com/swc-project/swc.git"
version = "0.23.0"
version = "0.24.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
Expand All @@ -31,19 +31,19 @@ relative-path = "1.2"
retain_mut = "0.1.2"
swc_atoms = {version = "0.2.4", path = "../atoms"}
swc_common = {version = "0.10.0", path = "../common"}
swc_ecma_ast = {version = "0.38.0", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.45.0", path = "../ecmascript/codegen"}
swc_ecma_parser = {version = "0.47.0", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.36.0", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.28.0", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.24.0", path = "../ecmascript/visit"}
swc_ecma_ast = {version = "0.39.0", path = "../ecmascript/ast"}
swc_ecma_codegen = {version = "0.46.0", path = "../ecmascript/codegen"}
swc_ecma_parser = {version = "0.48.0", path = "../ecmascript/parser"}
swc_ecma_transforms = {version = "0.37.0", path = "../ecmascript/transforms", features = ["optimization"]}
swc_ecma_utils = {version = "0.29.0", path = "../ecmascript/utils"}
swc_ecma_visit = {version = "0.25.0", path = "../ecmascript/visit"}

[dev-dependencies]
hex = "0.4"
ntest = "0.7.2"
reqwest = {version = "0.10.8", features = ["blocking"]}
sha-1 = "0.9"
swc_ecma_transforms = {version = "0.36.0", path = "../ecmascript/transforms", features = ["react", "typescript"]}
swc_ecma_transforms = {version = "0.37.0", path = "../ecmascript/transforms", features = ["react", "typescript"]}
tempfile = "3.1.0"
testing = {version = "0.10.0", path = "../testing"}
url = "2.1.1"
Expand Down
10 changes: 7 additions & 3 deletions bundler/src/bundler/chunk/cjs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ fn wrap_module(
Param {
span: DUMMY_SP,
decorators: Default::default(),
pat: Pat::Ident(Ident::new("module".into(), DUMMY_SP.with_ctxt(local_ctxt))),
pat: Pat::Ident(
Ident::new("module".into(), DUMMY_SP.with_ctxt(local_ctxt)).into(),
),
},
// exports
Param {
span: DUMMY_SP,
decorators: Default::default(),
pat: Pat::Ident(Ident::new("exports".into(), DUMMY_SP.with_ctxt(local_ctxt))),
pat: Pat::Ident(
Ident::new("exports".into(), DUMMY_SP.with_ctxt(local_ctxt)).into(),
),
},
],
decorators: vec![],
Expand Down Expand Up @@ -168,7 +172,7 @@ fn wrap_module(
declare: false,
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(load_var.clone()),
name: Pat::Ident(load_var.clone().into()),
init: Some(Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
callee: Ident::new("__spack_require__".into(), DUMMY_SP.with_ctxt(helper_ctxt))
Expand Down
16 changes: 9 additions & 7 deletions bundler/src/bundler/chunk/computed_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,32 @@ where
let decl = &var.decls[0];
match &decl.name {
Pat::Ident(i) => {
if i.sym == js_word!("default") {
if i.id.sym == js_word!("default") {
return Some(Stmt::Decl(Decl::Var(var)));
}

if let Some(remapped) = ctx.transitive_remap.get(&i.span.ctxt) {
if let Some(remapped) =
ctx.transitive_remap.get(&i.id.span.ctxt)
{
// Create
//
// const local = mod.local;
// expodt { local as exported }
//

let local_var = Ident::new(
i.sym.clone(),
i.span.with_ctxt(info.local_ctxt()),
i.id.sym.clone(),
i.id.span.with_ctxt(info.local_ctxt()),
);

let var_decl = VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(local_var.clone()),
name: Pat::Ident(local_var.clone().into()),
init: Some(Box::new(Expr::Member(MemberExpr {
span: DUMMY_SP,
obj: module_var_name.clone().as_obj(),
prop: {
let mut prop = i.clone();
let mut prop = i.id.clone();
prop.span.ctxt = SyntaxContext::empty();

Box::new(Expr::Ident(prop))
Expand Down Expand Up @@ -223,7 +225,7 @@ where
decls: vec![VarDeclarator {
span: DUMMY_SP,
definite: false,
name: Pat::Ident(module_var_name.into_ident()),
name: Pat::Ident(module_var_name.into_ident().into()),
init: Some(Box::new(module_expr)),
}],
};
Expand Down
13 changes: 8 additions & 5 deletions bundler/src/bundler/chunk/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn unexprt_as_var(modules: &mut Modules, dep_export_ctxt: SyntaxContext) {
{
decls.push(VarDeclarator {
span: n.span,
name: Pat::Ident(exported),
name: Pat::Ident(exported.into()),
init: Some(Box::new(Expr::Ident(n.orig.clone()))),
definite: true,
})
Expand All @@ -223,10 +223,13 @@ fn unexprt_as_var(modules: &mut Modules, dep_export_ctxt: SyntaxContext) {

decls.push(VarDeclarator {
span: n.span,
name: Pat::Ident(Ident::new(
n.orig.sym.clone(),
n.orig.span.with_ctxt(dep_export_ctxt),
)),
name: Pat::Ident(
Ident::new(
n.orig.sym.clone(),
n.orig.span.with_ctxt(dep_export_ctxt),
)
.into(),
),
init: Some(Box::new(Expr::Ident(n.orig.clone()))),
definite: false,
})
Expand Down
26 changes: 16 additions & 10 deletions bundler/src/bundler/chunk/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ where

let var_decl = &mut var.decls[0];
match &var_decl.name {
Pat::Ident(i) if id == *i => {}
Pat::Ident(i) if id == i.id => {}
_ => continue,
}

Expand Down Expand Up @@ -1321,10 +1321,13 @@ where
ModuleDecl::ExportDefaultDecl(ref mut export) => match &mut export.decl {
DefaultDecl::Class(expr) => {
let expr = expr.take();
let export_name = Pat::Ident(Ident::new(
js_word!("default"),
export.span.with_ctxt(info.export_ctxt()),
));
let export_name = Pat::Ident(
Ident::new(
js_word!("default"),
export.span.with_ctxt(info.export_ctxt()),
)
.into(),
);

let (init, s) = match expr.ident {
Some(name) => {
Expand Down Expand Up @@ -1423,10 +1426,13 @@ where
vars.push(
VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(Ident::new(
js_word!("default"),
DUMMY_SP.with_ctxt(info.export_ctxt()),
)),
name: Pat::Ident(
Ident::new(
js_word!("default"),
DUMMY_SP.with_ctxt(info.export_ctxt()),
)
.into(),
),
init: Some(export.expr.take()),
definite: false,
}
Expand Down Expand Up @@ -1641,7 +1647,7 @@ impl VisitMut for ImportMetaHandler<'_, '_> {
declare: false,
decls: vec![VarDeclarator {
span: n.span,
name: Pat::Ident(self.inline_ident.clone()),
name: Pat::Ident(self.inline_ident.clone().into()),
init: Some(Box::new(Expr::Object(ObjectLit {
span: n.span,
props: key_value_props
Expand Down
2 changes: 1 addition & 1 deletion bundler/src/bundler/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ where
))));
let var = VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(default_var),
name: Pat::Ident(default_var.into()),
init: Some(export.expr),
definite: false,
};
Expand Down
8 changes: 4 additions & 4 deletions bundler/src/bundler/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl VisitMut for KeywordRenamer {
key: PropName::Ident(pat.key.take()),
value: Box::new(Pat::Assign(AssignPat {
span: pat.span,
left: Box::new(Pat::Ident(renamed)),
left: Box::new(Pat::Ident(renamed.into())),
right: default.take(),
type_ann: None,
})),
Expand All @@ -87,7 +87,7 @@ impl VisitMut for KeywordRenamer {
None => {
*n = ObjectPatProp::KeyValue(KeyValuePatProp {
key: PropName::Ident(pat.key.take()),
value: Box::new(Pat::Ident(renamed)),
value: Box::new(Pat::Ident(renamed.into())),
})
}
}
Expand All @@ -100,8 +100,8 @@ impl VisitMut for KeywordRenamer {
fn visit_mut_pat(&mut self, n: &mut Pat) {
match n {
Pat::Ident(n) => {
if let Some(renamed) = self.renamed(&n) {
*n = renamed;
if let Some(renamed) = self.renamed(&n.id) {
*n = renamed.into();
}

return;
Expand Down
4 changes: 2 additions & 2 deletions bundler/src/bundler/modules/sort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ impl Visit for InitializerFinder {

fn visit_pat(&mut self, pat: &Pat, _: &dyn Node) {
match pat {
Pat::Ident(i) if self.ident == *i => {
Pat::Ident(i) if self.ident == i.id => {
self.found = true;
}

Expand Down Expand Up @@ -653,7 +653,7 @@ impl Visit for RequirementCalculartor {
if self.in_var_decl && !self.in_assign_lhs {
return;
}
self.insert(i.into());
self.insert((&i.id).into());
}
_ => {
pat.visit_children_with(self);
Expand Down
4 changes: 2 additions & 2 deletions bundler/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) trait ExprExt: Into<Expr> {

VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(Ident::new(lhs.0, DUMMY_SP.with_ctxt(lhs.1))),
name: Pat::Ident(Ident::new(lhs.0, DUMMY_SP.with_ctxt(lhs.1)).into()),
init: Some(Box::new(init)),
definite: false,
}
Expand Down Expand Up @@ -152,7 +152,7 @@ impl MapWithMut for ObjectPatProp {

impl MapWithMut for PatOrExpr {
fn dummy() -> Self {
PatOrExpr::Pat(Box::new(Pat::Ident(Ident::dummy())))
PatOrExpr::Pat(Box::new(Pat::Ident(Ident::dummy().into())))
}
}

Expand Down
16 changes: 8 additions & 8 deletions ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecmascript"
repository = "https://github.com/swc-project/swc.git"
version = "0.22.0"
version = "0.23.0"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -27,12 +27,12 @@ react = ["swc_ecma_transforms/react"]
typescript = ["swc_ecma_transforms/typescript"]

[dependencies]
swc_ecma_ast = {version = "0.38.0", path = "./ast"}
swc_ecma_codegen = {version = "0.45.0", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.15.0", path = "./dep-graph", optional = true}
swc_ecma_parser = {version = "0.47.0", path = "./parser", optional = true}
swc_ecma_transforms = {version = "0.36.0", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.28.0", path = "./utils", optional = true}
swc_ecma_visit = {version = "0.24.0", path = "./visit", optional = true}
swc_ecma_ast = {version = "0.39.0", path = "./ast"}
swc_ecma_codegen = {version = "0.46.0", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.16.0", path = "./dep-graph", optional = true}
swc_ecma_parser = {version = "0.48.0", path = "./parser", optional = true}
swc_ecma_transforms = {version = "0.37.0", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.29.0", path = "./utils", optional = true}
swc_ecma_visit = {version = "0.25.0", path = "./visit", optional = true}

[dev-dependencies]
2 changes: 1 addition & 1 deletion ecmascript/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_ast"
repository = "https://github.com/swc-project/swc.git"
version = "0.38.0"
version = "0.39.0"

[features]
default = []
Expand Down
Loading

0 comments on commit eaeffab

Please sign in to comment.