mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 04:47:03 +03:00
perf(es/minifier): Change default value of passes
to 3
(#4373)
This commit is contained in:
parent
aef1155311
commit
a8eb00cc54
@ -90,8 +90,8 @@ fn matrix() -> Vec<(String, Options)> {
|
||||
target: Some(target),
|
||||
minify: if minify {
|
||||
Some(from_json(
|
||||
"{ \"compress\": { \"toplevel\": true, \"module\": true }, \
|
||||
\"mangle\": false, \"toplevel\": true }",
|
||||
"{ \"compress\": { \"toplevel\": true, \"module\": true, \
|
||||
\"passes\": 0 }, \"mangle\": false, \"toplevel\": true }",
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,71 +1,72 @@
|
||||
export default function(c, e) {
|
||||
var a = 86400000, b = 7 * a, c = 365.25 * a;
|
||||
export default function(f, h) {
|
||||
try {
|
||||
if ("string" == typeof c && c.length > 0) return function(b) {
|
||||
if ((b = String(b)).length > 100) throw new Error("Value exceeds the maximum length of 100 characters.");
|
||||
var c = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(b);
|
||||
if (!c) return NaN;
|
||||
var a = parseFloat(c[1]), d = (c[2] || "ms").toLowerCase();
|
||||
switch(d){
|
||||
if ("string" == typeof f && f.length > 0) return function(e) {
|
||||
if ((e = String(e)).length > 100) throw new Error("Value exceeds the maximum length of 100 characters.");
|
||||
var f = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);
|
||||
if (!f) return NaN;
|
||||
var d = parseFloat(f[1]), g = (f[2] || "ms").toLowerCase();
|
||||
switch(g){
|
||||
case "years":
|
||||
case "year":
|
||||
case "yrs":
|
||||
case "yr":
|
||||
case "y":
|
||||
return 31557600000 * a;
|
||||
return d * c;
|
||||
case "weeks":
|
||||
case "week":
|
||||
case "w":
|
||||
return 604800000 * a;
|
||||
return d * b;
|
||||
case "days":
|
||||
case "day":
|
||||
case "d":
|
||||
return 86400000 * a;
|
||||
return d * a;
|
||||
case "hours":
|
||||
case "hour":
|
||||
case "hrs":
|
||||
case "hr":
|
||||
case "h":
|
||||
return 3600000 * a;
|
||||
return 3600000 * d;
|
||||
case "minutes":
|
||||
case "minute":
|
||||
case "mins":
|
||||
case "min":
|
||||
case "m":
|
||||
return 60000 * a;
|
||||
return 60000 * d;
|
||||
case "seconds":
|
||||
case "second":
|
||||
case "secs":
|
||||
case "sec":
|
||||
case "s":
|
||||
return 1000 * a;
|
||||
return 1000 * d;
|
||||
case "milliseconds":
|
||||
case "millisecond":
|
||||
case "msecs":
|
||||
case "msec":
|
||||
case "ms":
|
||||
return a;
|
||||
return d;
|
||||
default:
|
||||
throw new Error("The unit ".concat(d, " was matched, but no matching case exists."));
|
||||
throw new Error("The unit ".concat(g, " was matched, but no matching case exists."));
|
||||
}
|
||||
}(c);
|
||||
if ("number" == typeof c && isFinite(c)) return (null == e ? void 0 : e.long) ? b(c) : a(c);
|
||||
}(f);
|
||||
if ("number" == typeof f && isFinite(f)) return (null == h ? void 0 : h.long) ? e(f) : d(f);
|
||||
throw new Error("Value is not a string or number.");
|
||||
} catch (f) {
|
||||
var g = d(f) ? "".concat(f.message, ". value=").concat(JSON.stringify(c)) : "An unknown error has occurred.";
|
||||
throw new Error(g);
|
||||
} catch (i) {
|
||||
var j = g(i) ? "".concat(i.message, ". value=").concat(JSON.stringify(f)) : "An unknown error has occurred.";
|
||||
throw new Error(j);
|
||||
}
|
||||
};
|
||||
function a(a) {
|
||||
var b = Math.abs(a);
|
||||
return b >= 86400000 ? "".concat(Math.round(a / 86400000), "d") : b >= 3600000 ? "".concat(Math.round(a / 3600000), "h") : b >= 60000 ? "".concat(Math.round(a / 60000), "m") : b >= 1000 ? "".concat(Math.round(a / 1000), "s") : "".concat(a, "ms");
|
||||
function d(b) {
|
||||
var c = Math.abs(b);
|
||||
return c >= a ? "".concat(Math.round(b / a), "d") : c >= 3600000 ? "".concat(Math.round(b / 3600000), "h") : c >= 60000 ? "".concat(Math.round(b / 60000), "m") : c >= 1000 ? "".concat(Math.round(b / 1000), "s") : "".concat(b, "ms");
|
||||
}
|
||||
function b(b) {
|
||||
var a = Math.abs(b);
|
||||
return a >= 86400000 ? c(b, a, 86400000, "day") : a >= 3600000 ? c(b, a, 3600000, "hour") : a >= 60000 ? c(b, a, 60000, "minute") : a >= 1000 ? c(b, a, 1000, "second") : "".concat(b, " ms");
|
||||
function e(c) {
|
||||
var b = Math.abs(c);
|
||||
return b >= a ? f(c, b, a, "day") : b >= 3600000 ? f(c, b, 3600000, "hour") : b >= 60000 ? f(c, b, 60000, "minute") : b >= 1000 ? f(c, b, 1000, "second") : "".concat(c, " ms");
|
||||
}
|
||||
function c(b, c, a, d) {
|
||||
function f(b, c, a, d) {
|
||||
return "".concat(Math.round(b / a), " ").concat(d).concat(c >= 1.5 * a ? "s" : "");
|
||||
}
|
||||
function d(a) {
|
||||
function g(a) {
|
||||
return "object" == typeof a && null !== a && "message" in a;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ export default function n(e) {
|
||||
return !i(a) && !k(a);
|
||||
}).reduce(function(a, b) {
|
||||
return b.getSearchParameters(a);
|
||||
}, G), c = x.getWidgets().filter(function(a) {
|
||||
}, H), c = x.getWidgets().filter(function(a) {
|
||||
return Boolean(a.getSearchParameters);
|
||||
}).filter(function(a) {
|
||||
var b = i(a) && j(a, p), c = k(a) && l(a, p);
|
||||
@ -65,7 +65,7 @@ export default function n(e) {
|
||||
derivedParameters: e
|
||||
};
|
||||
}, B = function() {
|
||||
if (!E) {
|
||||
if (!F) {
|
||||
var a = s(r.state), b = a.mainParameters, c = a.derivedParameters;
|
||||
r.derivedHelpers.slice().forEach(function(a) {
|
||||
a.detach();
|
||||
@ -84,7 +84,7 @@ export default function n(e) {
|
||||
var f = y.getState(), g = !r.derivedHelpers.length, b = f.results ? f.results : {};
|
||||
b = !g && b.getFacetByName ? {} : b, b = g ? e.results : a.objectSpread({}, b, a.defineProperty({}, c, e.results));
|
||||
var d = y.getState(), h = d.isSearchStalled;
|
||||
r.hasPendingRequests() || (clearTimeout(F), F = null, h = !1), d.resultsFacetValues;
|
||||
r.hasPendingRequests() || (clearTimeout(G), G = null, h = !1), d.resultsFacetValues;
|
||||
var i = a.objectWithoutProperties(d, [
|
||||
"resultsFacetValues"
|
||||
]);
|
||||
@ -97,7 +97,7 @@ export default function n(e) {
|
||||
};
|
||||
}, u = function(d) {
|
||||
var e = d.error, b = y.getState(), c = b.isSearchStalled;
|
||||
r.hasPendingRequests() || (clearTimeout(F), c = !1), b.resultsFacetValues;
|
||||
r.hasPendingRequests() || (clearTimeout(G), c = !1), b.resultsFacetValues;
|
||||
var f = a.objectWithoutProperties(b, [
|
||||
"resultsFacetValues"
|
||||
]);
|
||||
@ -172,7 +172,7 @@ export default function n(e) {
|
||||
})));
|
||||
}, r = b(g, p, a.objectSpread({}, d));
|
||||
h(g), r.on("search", function() {
|
||||
F || (F = setTimeout(function() {
|
||||
!G && (G = setTimeout(function() {
|
||||
var b = y.getState(), c = (b.resultsFacetValues, a.objectWithoutProperties(b, [
|
||||
"resultsFacetValues"
|
||||
]));
|
||||
@ -183,7 +183,7 @@ export default function n(e) {
|
||||
}).on("result", t({
|
||||
indexId: p
|
||||
})).on("error", u);
|
||||
var f, v, w, E = !1, F = null, G = r.state, x = c(function() {
|
||||
var f, E, v, w, F = !1, G = null, H = r.state, x = c(function() {
|
||||
var b = A(y.getState().widgets);
|
||||
y.setState(a.objectSpread({}, y.getState(), {
|
||||
metadata: b,
|
||||
@ -307,13 +307,13 @@ export default function n(e) {
|
||||
h(a), r.setClient(a), B();
|
||||
},
|
||||
updateIndex: function(a) {
|
||||
G = G.setIndex(a);
|
||||
H = H.setIndex(a);
|
||||
},
|
||||
clearCache: function() {
|
||||
r.clearCache(), B();
|
||||
},
|
||||
skipSearch: function() {
|
||||
E = !0;
|
||||
F = !0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -6,11 +6,10 @@ use std::fs::read_to_string;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use swc_common::{sync::Lrc, FileName, Mark, SourceMap};
|
||||
use swc_ecma_ast::EsVersion;
|
||||
use swc_ecma_codegen::text_writer::JsWriter;
|
||||
use swc_ecma_minifier::{
|
||||
optimize,
|
||||
option::{CompressOptions, ExtraOptions, MangleOptions, MinifyOptions, PureGetterOption},
|
||||
option::{CompressOptions, ExtraOptions, MangleOptions, MinifyOptions},
|
||||
};
|
||||
use swc_ecma_parser::parse_file_as_module;
|
||||
use swc_ecma_transforms_base::{fixer::fixer, resolver::resolver_with_mark};
|
||||
@ -75,59 +74,7 @@ fn run(src: &str) {
|
||||
&MinifyOptions {
|
||||
rename: false,
|
||||
compress: Some(CompressOptions {
|
||||
arguments: false,
|
||||
arrows: true,
|
||||
bools: true,
|
||||
bools_as_ints: false,
|
||||
collapse_vars: true,
|
||||
comparisons: true,
|
||||
computed_props: false,
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
directives: false,
|
||||
drop_console: false,
|
||||
drop_debugger: true,
|
||||
ecma: EsVersion::Es2015,
|
||||
evaluate: true,
|
||||
expr: false,
|
||||
global_defs: Default::default(),
|
||||
hoist_fns: false,
|
||||
hoist_props: true,
|
||||
hoist_vars: false,
|
||||
ie8: false,
|
||||
if_return: true,
|
||||
inline: 3,
|
||||
join_vars: true,
|
||||
keep_classnames: false,
|
||||
keep_fargs: true,
|
||||
keep_fnames: false,
|
||||
keep_infinity: false,
|
||||
loops: true,
|
||||
module: false,
|
||||
negate_iife: true,
|
||||
passes: 0,
|
||||
props: true,
|
||||
pure_getters: PureGetterOption::Strict,
|
||||
reduce_fns: false,
|
||||
reduce_vars: false,
|
||||
sequences: 3,
|
||||
side_effects: true,
|
||||
switches: false,
|
||||
top_retain: Default::default(),
|
||||
top_level: None,
|
||||
typeofs: true,
|
||||
unsafe_passes: false,
|
||||
unsafe_arrows: false,
|
||||
unsafe_comps: false,
|
||||
unsafe_function: false,
|
||||
unsafe_math: false,
|
||||
unsafe_symbols: false,
|
||||
unsafe_methods: false,
|
||||
unsafe_proto: false,
|
||||
unsafe_regexp: false,
|
||||
unsafe_undefined: false,
|
||||
unused: true,
|
||||
const_to_let: true,
|
||||
..Default::default()
|
||||
}),
|
||||
mangle: Some(MangleOptions {
|
||||
props: None,
|
||||
|
@ -226,7 +226,7 @@ pub struct CompressOptions {
|
||||
|
||||
/// If this value is zero, the minifier will repeat work until the ast node
|
||||
/// is settled.
|
||||
#[serde(default = "zero_by_default")]
|
||||
#[serde(default = "default_passes")]
|
||||
#[serde(alias = "passes")]
|
||||
pub passes: usize,
|
||||
|
||||
@ -329,8 +329,8 @@ const fn true_by_default() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
const fn zero_by_default() -> usize {
|
||||
0
|
||||
const fn default_passes() -> usize {
|
||||
3
|
||||
}
|
||||
|
||||
const fn three_by_default() -> u8 {
|
||||
|
@ -8,7 +8,7 @@ use swc_ecma_ast::*;
|
||||
use swc_ecma_parser::parse_file_as_expr;
|
||||
use swc_ecma_utils::drop_span;
|
||||
|
||||
use super::{true_by_default, CompressOptions, TopLevelOptions};
|
||||
use super::{default_passes, true_by_default, CompressOptions, TopLevelOptions};
|
||||
use crate::option::PureGetterOption;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -166,7 +166,7 @@ pub struct TerserCompressorOptions {
|
||||
#[serde(default)]
|
||||
pub negate_iife: Option<bool>,
|
||||
|
||||
#[serde(default)]
|
||||
#[serde(default = "default_passes")]
|
||||
pub passes: usize,
|
||||
|
||||
#[serde(default)]
|
||||
|
@ -108,6 +108,9 @@ impl TestMangleOptions {
|
||||
struct TestOptions {
|
||||
#[serde(default)]
|
||||
defaults: bool,
|
||||
|
||||
#[serde(default)]
|
||||
passes: usize,
|
||||
}
|
||||
|
||||
fn parse_compressor_config(cm: Lrc<SourceMap>, s: &str) -> (bool, CompressOptions) {
|
||||
@ -118,6 +121,7 @@ fn parse_compressor_config(cm: Lrc<SourceMap>, s: &str) -> (bool, CompressOption
|
||||
|
||||
c.defaults = opts.defaults;
|
||||
c.const_to_let = Some(false);
|
||||
c.passes = opts.passes;
|
||||
|
||||
(c.module, c.into_config(cm))
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"defaults": true,
|
||||
"toplevel": true
|
||||
"toplevel": true,
|
||||
"passes": 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user