Skip to content

Commit

Permalink
fix(es/minifier): Don't drop used variables from sequential inliner (#…
Browse files Browse the repository at this point in the history
…6520)

**Related issue:**

 - Closes #6510.
  • Loading branch information
kdy1 authored Nov 29, 2022
1 parent 08e1c50 commit b394f9f
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ var a, x = {}, y = {
};
x = a, y = a, a = x, a = y;
var s = "fooo";
a = 123, a = !0, n = a = s, b = a, s = a, a = 123, a = !0, a = "string";
a = 123, a = !0, s = a = s, a = 123, a = !0, a = "string";
3 changes: 2 additions & 1 deletion crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,8 @@ where
if let Some(usage) = self.data.vars.get(&left_id.to_id()) {
// We are eliminating one usage, so we use 1 instead of
// 0
if !$force_drop && usage.usage_count == 1 {
if !$force_drop && usage.usage_count == 1 && usage.assign_count == 0
{
report_change!("sequences: Dropping inlined variable");
a.name.take();
}
Expand Down
26 changes: 26 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/next/joda/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";
(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[715], {

/***/ 3266:
/***/ (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "h": function () { return /* binding */ LocalDate; }
/* harmony export */
});

var isInit = false;

function init() {
if (isInit) {
return;
}

isInit = true;
}

init();

})

}]);
15 changes: 15 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/next/joda/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function() {
return LocalDate;
}
});
}
}
]);
26 changes: 26 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/1/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";
(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[715], {

/***/ 3266:
/***/ (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "h": function () { return /* binding */ LocalDate; }
/* harmony export */
});

var isInit = false;

function init() {
if (isInit) {
return;
}

isInit = true;
}

init();

})

}]);
19 changes: 19 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/1/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function() {
return LocalDate;
}
});
var isInit = !1;
!function() {
if (!isInit) isInit = !0;
}();
}
}
]);
19 changes: 19 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/2/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function () {
return LocalDate;
}
});
var isInit = !1;
!function () {
if (!isInit) isInit = !0;
}();
}
}
]);
17 changes: 17 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/joda/2/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
[
715
],
{
3266: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
h: function() {
return LocalDate;
}
});
var isInit = !1;
isInit = !0;
}
}
]);

1 comment on commit b394f9f

@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: b394f9f Previous: e3cbe7e Ratio
es/full/bugs-1 350508 ns/iter (± 29305) 376952 ns/iter (± 63545) 0.93
es/full/minify/libraries/antd 2111879218 ns/iter (± 98075579) 2206985732 ns/iter (± 42259483) 0.96
es/full/minify/libraries/d3 477253912 ns/iter (± 23150529) 484973260 ns/iter (± 39467533) 0.98
es/full/minify/libraries/echarts 1768784942 ns/iter (± 44996832) 1857187478 ns/iter (± 510194701) 0.95
es/full/minify/libraries/jquery 120848711 ns/iter (± 1356858) 130091506 ns/iter (± 20044770) 0.93
es/full/minify/libraries/lodash 139617902 ns/iter (± 9597166) 146377125 ns/iter (± 26383586) 0.95
es/full/minify/libraries/moment 69739935 ns/iter (± 3553422) 71872937 ns/iter (± 1502540) 0.97
es/full/minify/libraries/react 22974476 ns/iter (± 143473) 23211015 ns/iter (± 684772) 0.99
es/full/minify/libraries/terser 397168315 ns/iter (± 43026278) 383136017 ns/iter (± 18860054) 1.04
es/full/minify/libraries/three 659201334 ns/iter (± 35529274) 711727581 ns/iter (± 62140383) 0.93
es/full/minify/libraries/typescript 3985253857 ns/iter (± 60110808) 4053621880 ns/iter (± 71180315) 0.98
es/full/minify/libraries/victory 956683828 ns/iter (± 30089334) 999038812 ns/iter (± 62498851) 0.96
es/full/minify/libraries/vue 185152232 ns/iter (± 4541908) 192076773 ns/iter (± 10135522) 0.96
es/full/codegen/es3 33985 ns/iter (± 1272) 34210 ns/iter (± 5190) 0.99
es/full/codegen/es5 34084 ns/iter (± 656) 33777 ns/iter (± 4969) 1.01
es/full/codegen/es2015 34032 ns/iter (± 631) 33849 ns/iter (± 4475) 1.01
es/full/codegen/es2016 33974 ns/iter (± 802) 34213 ns/iter (± 5357) 0.99
es/full/codegen/es2017 34080 ns/iter (± 1291) 33764 ns/iter (± 4339) 1.01
es/full/codegen/es2018 34071 ns/iter (± 648) 33728 ns/iter (± 3952) 1.01
es/full/codegen/es2019 34126 ns/iter (± 374) 33797 ns/iter (± 1742) 1.01
es/full/codegen/es2020 34227 ns/iter (± 1533) 34018 ns/iter (± 1077) 1.01
es/full/all/es3 205468621 ns/iter (± 11777873) 213102648 ns/iter (± 20481603) 0.96
es/full/all/es5 187566358 ns/iter (± 14030526) 195372280 ns/iter (± 18757534) 0.96
es/full/all/es2015 148442741 ns/iter (± 11936301) 155940559 ns/iter (± 14707035) 0.95
es/full/all/es2016 146573299 ns/iter (± 9311702) 150608362 ns/iter (± 16151921) 0.97
es/full/all/es2017 145423013 ns/iter (± 8809769) 149342192 ns/iter (± 12163642) 0.97
es/full/all/es2018 145189265 ns/iter (± 8078586) 148412554 ns/iter (± 17358285) 0.98
es/full/all/es2019 144159830 ns/iter (± 8356838) 147093097 ns/iter (± 16962553) 0.98
es/full/all/es2020 138094151 ns/iter (± 7190825) 141669916 ns/iter (± 9577567) 0.97
es/full/parser 730601 ns/iter (± 47270) 735105 ns/iter (± 43330) 0.99
es/full/base/fixer 26442 ns/iter (± 734) 26692 ns/iter (± 2253) 0.99
es/full/base/resolver_and_hygiene 91909 ns/iter (± 3392) 93471 ns/iter (± 12030) 0.98
serialization of ast node 217 ns/iter (± 7) 217 ns/iter (± 11) 1
serialization of serde 221 ns/iter (± 2) 223 ns/iter (± 32) 0.99

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

Please sign in to comment.