-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Performance regression for collapse_vars=true with many var defs of complex objects #50
Comments
@mlwilkerson Thanks for the report and self-contained repro. This also affects Reported upstream: mishoo/UglifyJS#3174 |
@mlwilkerson Please try out this patch on this and larger real life scenarios and report your findings. --- a/lib/compress.js
+++ b/lib/compress.js
@@ -1384,7 +1384,12 @@ merge(Compressor.prototype, {
extract_candidates(expr.alternative);
} else if (expr instanceof AST_Definitions
&& (compressor.option("unused") || !(expr instanceof AST_Const))) {
- expr.definitions.forEach(extract_candidates);
+ var len = expr.definitions.length;
+ var i = len - 200; // limit number of trailing variable defs for consideration
+ if (i < 0) i = 0;
+ for (; i < len; i++) {
+ extract_candidates(expr.definitions[i]);
+ }
} else if (expr instanceof AST_DWLoop) {
extract_candidates(expr.condition);
if (!(expr.body instanceof AST_Block)) { Without patch:
With patch:
Minified output appears to be the same. |
Thanks, @kzc. I'm on it. |
@kzc I can confirm that this patch solves the problem I've reported. Supporting evidence: Scenario 1: Webpack 4 bundle
Scenario 2: Webpack 4 bundle
Scenario 3: angular-cli "hello world"
without patch: 145s Scenario 4: real world Angular project
without patch, deep imports: 55s h/t @devoto13 for running some of these scenarios |
@mlwilkerson Thanks for reporting your findings. Speed and size aside, can I assume that all these minified programs ran correctly? |
Yes, that's a safe assumption that they all ran correctly. In my many runs I've not always verified the correctness of the output, but any time that I have spot-checked (maybe 50% of the time), it's always looked correct (properly tree-shaken), and always executed correctly. To be more certain, I did just re-verify the correctness of the minified programs for Scenario 1 and 2 above. Both ran correctly. I feel highly confident that Scenarios 3 and 4 would also be correct, but I have not verified. @devoto13 can you verify? |
@mlwilkerson Yes, both bundles work correctly. |
Thanks |
Bug report or Feature request?
Bug: 55x performance regression
Version (complete output of
terser -V
)terser 3.7.6
Complete CLI command or
minify()
options usedterser --compress collapse_vars=true --output output.js index.js
terser
inputInput is a module with many var defs, where each has a value that is a complex object. Original scenario was a webpack 4 bundle that had imported Font Awesome 5 icons.
This reproduction repo is a more minimal cleaned up demonstration.
Quick link to the input module from that repo.
terser
output or errorThis version of terser takes about 30 seconds to produce the bundle, depending on hardware. The output is correct, but this is very slow, and becomes significantly slower in other similar real-world scenarios.
Expected result
This should build in <1 second, depending on hardware. I've seen the same code build correctly as quickly as 0.4 seconds in some previous versions of
uglify-js
anduglify-es
that use the samecollapse_vars
compression option.I've timed my scenario against several snapshots of the
terser
code base and found that the performance has changed significantly as work oncompress.js:collapse()
has been done. For example:The text was updated successfully, but these errors were encountered: