Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(babel/compat): Improve performance of babelify #1626

Merged
merged 95 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
cfeef7e
Initialize babel plugin
kdy1 May 1, 2021
ffcd794
Ignore logs of cargo fmt
kdy1 May 1, 2021
d5ae4f8
Disable yarn workspace
kdy1 May 1, 2021
9810581
Yarn workspace for node modules
kdy1 May 1, 2021
21c50b2
TypeScript
kdy1 May 1, 2021
d544b1b
fmt
kdy1 May 1, 2021
e79bc7b
ci
kdy1 May 1, 2021
35f22e1
I need to think about api.
kdy1 May 1, 2021
3c96abb
Add dep
kdy1 May 1, 2021
c5392ef
Determined api
kdy1 May 1, 2021
ff402ee
Doc
kdy1 May 1, 2021
1a80885
Change api
kdy1 May 1, 2021
be46bde
WIP: Benchmark for babelify
kdy1 May 1, 2021
a53fe64
fixup for rebase
kdy1 May 3, 2021
1e01d5d
fmt
kdy1 May 3, 2021
44f884f
Fix benchmark
kdy1 May 3, 2021
09406d3
Rename
kdy1 May 3, 2021
173586b
Fixing...
kdy1 May 3, 2021
37f5623
Fixing stack overflow
kdy1 May 3, 2021
69ada06
Don't use env var
kdy1 May 3, 2021
e1ba9e5
Fix
kdy1 May 3, 2021
4f3f7c3
Lints
kdy1 May 3, 2021
9139710
Fix benchmark
kdy1 May 3, 2021
da29aaf
Add babelify.rs
kdy1 May 3, 2021
152f4b2
Add full benchmarks for babelify
kdy1 May 3, 2021
3c58453
Fix
kdy1 May 3, 2021
628af8a
WIP: Reduce memory allocation and copy
kdy1 May 3, 2021
4c90f3f
fixup: Reduce memory operations.
kdy1 May 3, 2021
df88666
Reduce clone
kdy1 May 3, 2021
0ebb73d
fixup
kdy1 May 3, 2021
86b348f
fixup
kdy1 May 3, 2021
77ed709
fixup
kdy1 May 3, 2021
b9e328f
fixup
kdy1 May 3, 2021
c813bd1
fixup
kdy1 May 3, 2021
3afc684
fixup
kdy1 May 3, 2021
77e594e
fixup
kdy1 May 3, 2021
70aebc4
Remove unnecessary clones.
kdy1 May 3, 2021
27572d5
Cleanup
kdy1 May 3, 2021
af55211
Cleanup
kdy1 May 3, 2021
abf150b
fixup
kdy1 May 3, 2021
f3cb3fe
Reduce sourcemap operations
kdy1 May 3, 2021
391d5d5
Optimize sourcemap operations of swc_common.
kdy1 May 3, 2021
c9e629a
More optimization
kdy1 May 3, 2021
c6b913e
Reduce creationg of string using new api.
kdy1 May 3, 2021
36bb8be
Use custom allocator while doing benchmarks
kdy1 May 3, 2021
ac18674
SIMD
kdy1 May 3, 2021
bdc57c2
rayon
kdy1 May 4, 2021
8071aa0
Use rayon
kdy1 May 4, 2021
8ab3927
Revert "Use rayon"
kdy1 May 4, 2021
a7a26ed
Moving crates
kdy1 May 4, 2021
3074ca5
fixup
kdy1 May 4, 2021
084ddcc
WIP: Move more codes
kdy1 May 4, 2021
043eb7a
fixup
kdy1 May 4, 2021
950c785
fixup
kdy1 May 4, 2021
20488bb
Remove
kdy1 May 4, 2021
729e797
WIP: Comment optimization
kdy1 May 4, 2021
32ed4b5
fixup
kdy1 May 4, 2021
af3fc5f
Optimize comment operations.
kdy1 May 4, 2021
d6c9233
fmt
kdy1 May 4, 2021
8b2e16c
Parallel
kdy1 May 4, 2021
7b5e031
parallel: 16 for stmt / module item
kdy1 May 4, 2021
0e573a9
Optimize further
kdy1 May 4, 2021
4aa4235
Update rustc
kdy1 May 4, 2021
e7154bd
jemalloc
kdy1 May 4, 2021
15f08a2
Remove useless main.rs
kdy1 May 4, 2021
4e3093a
Fix
kdy1 May 4, 2021
e0e035b
dev deps
kdy1 May 4, 2021
e29a25c
Workaround https://github.com/rust-lang/rust/issues/64402
kdy1 May 4, 2021
2a106b2
Fix lint
kdy1 May 4, 2021
55c5c92
Cleanup codes for allocator by using swc_node_base
kdy1 May 4, 2021
f950513
copyless
kdy1 May 4, 2021
3193bd4
Use copyless
kdy1 May 4, 2021
8210d7f
Rename
kdy1 May 4, 2021
973db1a
fxhash
kdy1 May 4, 2021
4c0319b
Use fxhash
kdy1 May 4, 2021
d1e414b
Lint
kdy1 May 4, 2021
cd213f2
Rename
kdy1 May 4, 2021
a51e632
fmt
kdy1 May 4, 2021
265ead3
Fix
kdy1 May 4, 2021
9bd0cab
Fix compilation
kdy1 May 4, 2021
f3d38d2
Move
kdy1 May 4, 2021
3173b0c
fixup
kdy1 May 4, 2021
8a981d0
Fix benchmarks
kdy1 May 4, 2021
71293f2
Use ahash instead of fxhash
kdy1 May 4, 2021
5b97595
Use compile time rng for ahash
kdy1 May 4, 2021
c5dde0c
print
kdy1 May 5, 2021
8b404fa
Fix
kdy1 May 5, 2021
3ced524
WIP: babelify
kdy1 May 5, 2021
889beab
fixup
kdy1 May 5, 2021
14dd59b
WIP
kdy1 May 5, 2021
22ec424
Merge branch 'master' into babel
kdy1 May 6, 2021
117ea9d
Move
kdy1 May 5, 2021
7050bf1
Let's split the pr
kdy1 May 6, 2021
371ede0
fixup
kdy1 May 6, 2021
6bb79b7
Merge branch 'master' into babel
kdy1 May 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[build]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
"-C", "target-feature=+sse2",
"-C", "target-feature=+sse2,+aes",
]

rustdocflags = [
Expand All @@ -12,6 +12,7 @@ rustdocflags = [
[target.aarch64-apple-darwin]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
"-C", "target-feature=+sse2,+aes"
]

[target.aarch64-unknown-linux-gnu]
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
fmt:
name: fmt
runs-on: ubuntu-latest
env:
RUST_LOG: "0"
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -99,10 +101,14 @@ jobs:
- enum_kind
- from_variant
- jsdoc
- node
- spack
- string_enum
- swc
- swc_atoms
- swc_babel_ast
- swc_babel_compat
- swc_babel_visit
- swc_bundler
- swc_common
- swc_ecma_ast
Expand Down Expand Up @@ -132,6 +138,7 @@ jobs:
- swc_visit_macros
- testing
- testing_macros
- wasm
exclude:
- os: windows-2019
crate: spack
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ version = "0.16.0"
name = "swc"

[dependencies]
ahash = "0.7.2"
anyhow = "1"
base64 = "0.12.0"
dashmap = "4.0.2"
Expand Down Expand Up @@ -44,6 +45,7 @@ swc_ecma_transforms = {version = "0.46.0", path = "./ecmascript/transforms", fea
]}
swc_ecma_utils = {version = "0.34.1", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.29.1", path = "./ecmascript/visit"}
swc_node_base = {path = "./node/base"}
swc_visit = {version = "0.2.3", path = "./visit"}

[dev-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion native/babel-ast/Cargo.toml → babel/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ version = "0.1.0"
[dependencies]
serde = {version = "1", features = ["derive"]}
serde_json = "1.0.62"
swc_common = {version = "0.10.9", path = "../../common"}
swc_atoms = {path = "../../atoms"}
swc_common = {path = "../../common"}
swc_node_base = {path = "../../node/base"}
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions native/babel-ast/src/common.rs → babel/ast/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use serde::{Deserialize, Serialize};
use swc_common::ast_serde;

use crate::{
class::*, comment::Comment, decl::*, expr::*, flow::*, jsx::*, lit::*, module::*, object::*,
pat::*, stmt::*, typescript::*,
};
use serde::{Deserialize, Serialize};
use swc_atoms::JsWord;
use swc_common::ast_serde;

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -371,7 +371,7 @@ pub struct Identifier {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub name: String,
pub name: JsWord,
#[serde(default)]
pub decorators: Option<Vec<Decorator>>,
#[serde(default)]
Expand Down Expand Up @@ -559,7 +559,7 @@ pub struct DirectiveLiteral {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub value: String,
pub value: JsWord,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions native/babel-ast/src/expr.rs → babel/ast/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use serde::{Deserialize, Serialize};
use swc_common::ast_serde;

use crate::{
class::{ClassBody, ClassImpl},
common::{
Expand All @@ -22,6 +19,9 @@ use crate::{
TSAsExpression, TSNonNullExpression, TSTypeAssertion, TSTypeParameterInstantiation,
},
};
use serde::{Deserialize, Serialize};
use swc_atoms::JsWord;
use swc_common::ast_serde;

#[derive(Debug, Clone, PartialEq)]
#[ast_serde]
Expand Down Expand Up @@ -155,7 +155,7 @@ pub struct AssignmentExpression {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub operator: String,
pub operator: JsWord,
pub left: Box<LVal>,
pub right: Box<Expression>,
}
Expand Down Expand Up @@ -258,7 +258,7 @@ pub struct V8IntrinsicIdentifier {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub name: String,
pub name: JsWord,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
5 changes: 3 additions & 2 deletions native/babel-ast/src/flow.rs → babel/ast/src/flow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use swc_atoms::JsWord;
use swc_common::ast_serde;

use crate::{
Expand Down Expand Up @@ -361,7 +362,7 @@ pub struct TypeParameter {
#[serde(default)]
pub variance: Option<Variance>,
#[serde(default)]
pub name: String,
pub name: JsWord,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -564,7 +565,7 @@ pub struct StringLiteralTypeAnnotation {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub value: String,
pub value: JsWord,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down
5 changes: 3 additions & 2 deletions native/babel-ast/src/jsx.rs → babel/ast/src/jsx.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use swc_atoms::JsWord;
use swc_common::ast_serde;

use crate::{
Expand Down Expand Up @@ -133,7 +134,7 @@ pub struct JSXIdentifier {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub name: String,
pub name: JsWord,
}

impl From<Identifier> for JSXIdentifier {
Expand Down Expand Up @@ -218,7 +219,7 @@ pub struct JSXSpreadAttribute {
pub struct JSXText {
#[serde(flatten)]
pub base: BaseNode,
pub value: String,
pub value: JsWord,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
3 changes: 3 additions & 0 deletions native/babel-ast/src/lib.rs → babel/ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![feature(macro_attributes_in_derive_output)]

/// Explicit extern crate to use global allocator.
extern crate swc_node_base;

mod class;
mod comment;
mod common;
Expand Down
20 changes: 10 additions & 10 deletions native/babel-ast/src/lit.rs → babel/ast/src/lit.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{common::BaseNode, expr::Expression, typescript::TSType};
use serde::{Deserialize, Serialize};
use swc_atoms::JsWord;
use swc_common::ast_serde;

use crate::{common::BaseNode, expr::Expression, typescript::TSType};

#[derive(Debug, Clone, PartialEq)]
#[ast_serde]
pub enum Literal {
Expand All @@ -29,7 +29,7 @@ pub enum Literal {
pub struct StringLiteral {
#[serde(flatten)]
pub base: BaseNode,
pub value: String,
pub value: JsWord,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -69,9 +69,9 @@ pub struct BooleanLiteral {
pub struct RegExpLiteral {
#[serde(flatten)]
pub base: BaseNode,
pub pattern: String,
pub pattern: JsWord,
#[serde(default)]
pub flags: String,
pub flags: JsWord,
}

/// Deprecated. Use RegExpLiteral instead.
Expand All @@ -80,17 +80,17 @@ pub struct RegExpLiteral {
pub struct RegexLiteral {
#[serde(flatten)]
pub base: BaseNode,
pub pattern: String,
pub pattern: JsWord,
#[serde(default)]
pub flags: String,
pub flags: JsWord,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TemplateElVal {
#[serde(default)]
pub raw: String,
pub raw: JsWord,
#[serde(default)]
pub cooked: Option<String>,
pub cooked: Option<JsWord>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -172,5 +172,5 @@ pub struct DecimalLiteral {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub value: String,
pub value: JsWord,
}
10 changes: 5 additions & 5 deletions native/babel-ast/src/module.rs → babel/ast/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use swc_common::ast_serde;

use crate::{
class::ClassDeclaration,
comment::Comment,
Expand All @@ -12,6 +8,10 @@ use crate::{
stmt::Statement,
typescript::TSDeclareFunction,
};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use swc_atoms::JsWord;
use swc_common::ast_serde;

#[derive(Debug, Clone, PartialEq)]
#[ast_serde]
Expand Down Expand Up @@ -72,7 +72,7 @@ pub struct InterpreterDirective {
#[serde(flatten)]
pub base: BaseNode,
#[serde(default)]
pub value: String,
pub value: JsWord,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use swc_atoms::JsWord;
use swc_common::ast_serde;

use crate::{
Expand Down Expand Up @@ -641,7 +642,7 @@ pub struct TSTypeOperator {
pub base: BaseNode,
pub type_annotation: Box<TSType>,
#[serde(default)]
pub operator: String,
pub operator: JsWord,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -913,5 +914,5 @@ pub struct TSTypeParameter {
#[serde(default)]
pub default: Option<Box<TSType>>,
#[serde(default)]
pub name: String,
pub name: JsWord,
}
10 changes: 7 additions & 3 deletions native/babel-compat/Cargo.toml → babel/compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ahash = "0.7.0"
ahash = {version = "0.7.0", features = ["compile-time-rng"]}
anyhow = "1"
copyless = "0.1.5"
rayon = "1.5.0"
serde = {version = "1", features = ["derive"]}
serde_json = "1.0.62"
swc = {path = "../.."}
swc_atoms = {version = "0.2.5", path = "../../atoms"}
swc_babel_ast = {path = "../babel-ast"}
swc_babel_visit = {path = "../babel-visit"}
swc_babel_ast = {path = "../ast"}
swc_babel_visit = {path = "../visit"}
swc_common = {version = "0.10.9", path = "../../common", features = ["tty-emitter", "sourcemap"]}
swc_ecma_ast = {version = "0.43", path = "../../ecmascript/ast"}
swc_ecma_parser = {version = "0.54.2", path = "../../ecmascript/parser"}
swc_ecma_visit = {version = "0.29.1", path = "../../ecmascript/visit"}
swc_node_base = {path = "../../node/base"}

[dev-dependencies]
pretty_assertions = "0.7.1"
swc_ecma_transforms = {path = "../../ecmascript/transforms/"}
walkdir = "2"
File renamed without changes.
Loading