Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/minifier): Implement trivial optimizations (#6256)
**Description:** 1. Evaluate `Number.toString()`. 2. Mark some terser tests as passing where our output is better.
- Loading branch information
Showing
20 changed files
with
117 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function fn(bar) { | ||
var foo = 64206..toString(16); | ||
var foo = "face"; | ||
return eval(bar); | ||
} | ||
console.log(fn("foo + bar")); |
1 change: 0 additions & 1 deletion
1
crates/swc/tests/tsc-references/propertyAccessNumericLiterals.es6.2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
//// [propertyAccessNumericLiterals.es6.ts] | ||
0xffffffff.toString(), 0o01234.toString(), 0b01101101.toString(), 1234..toString(), 1e0.toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
crates/swc_ecma_minifier/tests/pass-default/compute/1/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
console.log(1588444911..toString(16)); | ||
console.log("5eadbeef"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
crates/swc_ecma_minifier/tests/terser/compress/destructuring/issue_3205_2/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
(function () { | ||
function f() { | ||
var o = { a: "PASS" }, | ||
{ a: x } = o; | ||
console.log(x); | ||
} | ||
f(); | ||
(function() { | ||
var { a: x } = { | ||
a: "PASS" | ||
}; | ||
console.log(x); | ||
})(); |
11 changes: 5 additions & 6 deletions
11
crates/swc_ecma_minifier/tests/terser/compress/destructuring/issue_3205_3/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
(function () { | ||
function f(o, { a: x } = o) { | ||
console.log(x); | ||
} | ||
f({ a: "PASS" }); | ||
})(); | ||
(function(o, { a: x } = o) { | ||
console.log(x); | ||
})({ | ||
a: "PASS" | ||
}); |
13 changes: 6 additions & 7 deletions
13
crates/swc_ecma_minifier/tests/terser/compress/destructuring/issue_3205_4/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
(function () { | ||
function f(o) { | ||
var { a: x } = o; | ||
console.log(x); | ||
} | ||
f({ a: "PASS" }); | ||
})(); | ||
(function(o) { | ||
var { a: x } = o; | ||
console.log(x); | ||
})({ | ||
a: "PASS" | ||
}); |
5 changes: 2 additions & 3 deletions
5
crates/swc_ecma_minifier/tests/terser/compress/drop_unused/issue_2418_1/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
class C {} | ||
class C { | ||
} | ||
function F() {} | ||
(class {}); | ||
(function () {}); |
5 changes: 2 additions & 3 deletions
5
crates/swc_ecma_minifier/tests/terser/compress/drop_unused/issue_2418_2/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
class C {} | ||
class C { | ||
} | ||
function F() {} | ||
(class {}); | ||
(function () {}); |
5 changes: 2 additions & 3 deletions
5
crates/swc_ecma_minifier/tests/terser/compress/drop_unused/issue_2418_3/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
class C {} | ||
class C { | ||
} | ||
function F() {} | ||
(class {}); | ||
(function f() {}); |
16 changes: 14 additions & 2 deletions
16
crates/swc_ecma_minifier/tests/terser/compress/harmony/issue_1898/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
class Foo { | ||
bar() { | ||
for (const f of [6, 5]) | ||
for (let r of [4, 3]) for (var o of [2, 1]) console.log(f, r, o); | ||
for (const o of [ | ||
6, | ||
5 | ||
]){ | ||
for (let f of [ | ||
4, | ||
3 | ||
]){ | ||
for (var r of [ | ||
2, | ||
1 | ||
])console.log(o, f, r); | ||
} | ||
} | ||
} | ||
} | ||
new Foo().bar(); |
Oops, something went wrong.
5d52ae9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/bugs-1
333499
ns/iter (± 19664
)338587
ns/iter (± 25065
)0.98
es/full/minify/libraries/antd
1821367285
ns/iter (± 21294944
)1819540785
ns/iter (± 39172952
)1.00
es/full/minify/libraries/d3
395646308
ns/iter (± 15568813
)393708825
ns/iter (± 15261028
)1.00
es/full/minify/libraries/echarts
1529611573
ns/iter (± 17266138
)1574781134
ns/iter (± 46269988
)0.97
es/full/minify/libraries/jquery
97840769
ns/iter (± 1514192
)98076612
ns/iter (± 2586366
)1.00
es/full/minify/libraries/lodash
115607946
ns/iter (± 1698643
)116716696
ns/iter (± 6988872
)0.99
es/full/minify/libraries/moment
57688801
ns/iter (± 884911
)57798336
ns/iter (± 1135112
)1.00
es/full/minify/libraries/react
20075903
ns/iter (± 419054
)19932541
ns/iter (± 309578
)1.01
es/full/minify/libraries/terser
317650668
ns/iter (± 12046523
)304546184
ns/iter (± 24425600
)1.04
es/full/minify/libraries/three
545790497
ns/iter (± 14480442
)553245544
ns/iter (± 21562229
)0.99
es/full/minify/libraries/typescript
3278454545
ns/iter (± 71952773
)3567407570
ns/iter (± 328106135
)0.92
es/full/minify/libraries/victory
829572867
ns/iter (± 12864134
)919712489
ns/iter (± 153495738
)0.90
es/full/minify/libraries/vue
150604834
ns/iter (± 6633383
)177927025
ns/iter (± 44923356
)0.85
es/full/codegen/es3
33425
ns/iter (± 622
)35298
ns/iter (± 1092
)0.95
es/full/codegen/es5
33446
ns/iter (± 431
)35433
ns/iter (± 2095
)0.94
es/full/codegen/es2015
33111
ns/iter (± 727
)35370
ns/iter (± 2469
)0.94
es/full/codegen/es2016
33354
ns/iter (± 869
)35745
ns/iter (± 3829
)0.93
es/full/codegen/es2017
33367
ns/iter (± 1849
)35002
ns/iter (± 7148
)0.95
es/full/codegen/es2018
33350
ns/iter (± 1547
)34764
ns/iter (± 24937
)0.96
es/full/codegen/es2019
33220
ns/iter (± 911
)34357
ns/iter (± 712
)0.97
es/full/codegen/es2020
33246
ns/iter (± 735
)34312
ns/iter (± 780
)0.97
es/full/all/es3
186887264
ns/iter (± 10693052
)194867417
ns/iter (± 29601477
)0.96
es/full/all/es5
176958837
ns/iter (± 6813676
)189184617
ns/iter (± 31849484
)0.94
es/full/all/es2015
142058528
ns/iter (± 5555615
)149887284
ns/iter (± 47027125
)0.95
es/full/all/es2016
142416710
ns/iter (± 6560502
)158736880
ns/iter (± 43394885
)0.90
es/full/all/es2017
140753085
ns/iter (± 6150161
)179692741
ns/iter (± 25671927
)0.78
es/full/all/es2018
140376638
ns/iter (± 8008789
)147805896
ns/iter (± 41638402
)0.95
es/full/all/es2019
145081774
ns/iter (± 5920782
)152004701
ns/iter (± 44630873
)0.95
es/full/all/es2020
139443199
ns/iter (± 7624274
)159153191
ns/iter (± 44342181
)0.88
es/full/parser
731386
ns/iter (± 27637
)759275
ns/iter (± 118680
)0.96
es/full/base/fixer
26935
ns/iter (± 1774
)27289
ns/iter (± 1882
)0.99
es/full/base/resolver_and_hygiene
91564
ns/iter (± 3220
)95250
ns/iter (± 31241
)0.96
serialization of ast node
213
ns/iter (± 2
)218
ns/iter (± 8
)0.98
serialization of serde
213
ns/iter (± 3
)216
ns/iter (± 12
)0.99
This comment was automatically generated by workflow using github-action-benchmark.