From 97cd190654f9a088f77502992a3fea6e22c242c9 Mon Sep 17 00:00:00 2001 From: kzc Date: Sun, 26 Jun 2016 17:16:02 -0400 Subject: [PATCH 1/3] Allow sequences maximum length to be user configurable. --- README.md | 7 ++++++- lib/compress.js | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2ab9de62..c0730874 100644 --- a/README.md +++ b/README.md @@ -289,7 +289,12 @@ you can pass a comma-separated list of options. Options are in the form `foo=bar`, or just `foo` (the latter implies a boolean option that you want to set `true`; it's effectively a shortcut for `foo=true`). -- `sequences` -- join consecutive simple statements using the comma operator +- `sequences` (default: true) -- join consecutive simple statements using the + comma operator. May be set to a positive integer to specify the maximum number + of consecutive comma sequences that will be generated. If this option is set to + `true` then the default sequences limit is `2000`. Set option to `false` or `0` + to disable. On rare occasions the default sequences limit leads to very slow + compress times in which case a value of `20` or less is recommended. - `properties` -- rewrite property access using the dot notation, for example `foo["bar"] → foo.bar` diff --git a/lib/compress.js b/lib/compress.js index 4152bd06..3da51abb 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -79,6 +79,8 @@ function Compressor(options, false_by_default) { global_defs : {}, passes : 1, }, true); + var sequences = this.options["sequences"]; + this.sequences_limit = sequences == 1 ? 2000 : sequences | 0; this.warnings_produced = {}; }; @@ -266,7 +268,7 @@ merge(Compressor.prototype, { if (compressor.option("if_return")) { statements = handle_if_return(statements, compressor); } - if (compressor.option("sequences")) { + if (compressor.sequences_limit > 0) { statements = sequencesize(statements, compressor); } if (compressor.option("join_vars")) { @@ -721,7 +723,7 @@ merge(Compressor.prototype, { seq = []; }; statements.forEach(function(stat){ - if (stat instanceof AST_SimpleStatement && seqLength(seq) < 2000) { + if (stat instanceof AST_SimpleStatement && seqLength(seq) < compressor.sequences_limit) { seq.push(stat.body); } else { push_seq(); From fd5a76ac52f9fb5427c2b5a3311dfbed4510365a Mon Sep 17 00:00:00 2001 From: kzc Date: Thu, 30 Jun 2016 14:56:12 -0400 Subject: [PATCH 2/3] Change the default sequences limit to 200 to speed up compress. Has little or no impact on minification size in the majority of cases but can speed up rollup builds significantly. This sequences change also has the beneficial side effect of avoiding "stack size exceeded" errors on very large input files. The user is free to alter the sequences limit if they are so inclined. The previous sequences limit was 2000. 20 is often sufficient. --- README.md | 2 +- lib/compress.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c0730874..721fa61b 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,7 @@ to set `true`; it's effectively a shortcut for `foo=true`). - `sequences` (default: true) -- join consecutive simple statements using the comma operator. May be set to a positive integer to specify the maximum number of consecutive comma sequences that will be generated. If this option is set to - `true` then the default sequences limit is `2000`. Set option to `false` or `0` + `true` then the default sequences limit is `200`. Set option to `false` or `0` to disable. On rare occasions the default sequences limit leads to very slow compress times in which case a value of `20` or less is recommended. diff --git a/lib/compress.js b/lib/compress.js index 3da51abb..bd5e5f3a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -80,7 +80,7 @@ function Compressor(options, false_by_default) { passes : 1, }, true); var sequences = this.options["sequences"]; - this.sequences_limit = sequences == 1 ? 2000 : sequences | 0; + this.sequences_limit = sequences == 1 ? 200 : sequences | 0; this.warnings_produced = {}; }; From 3502bd101d41e03419f53ef9e3aaab4bba67eff1 Mon Sep 17 00:00:00 2001 From: kzc Date: Thu, 30 Jun 2016 16:54:52 -0400 Subject: [PATCH 3/3] Document that the smallest sequences optimization length is 2 and a sequences value of 1 is considered to be `true` - which will be set to the default value of 200. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 721fa61b..2bdd1ffd 100644 --- a/README.md +++ b/README.md @@ -292,9 +292,11 @@ to set `true`; it's effectively a shortcut for `foo=true`). - `sequences` (default: true) -- join consecutive simple statements using the comma operator. May be set to a positive integer to specify the maximum number of consecutive comma sequences that will be generated. If this option is set to - `true` then the default sequences limit is `200`. Set option to `false` or `0` - to disable. On rare occasions the default sequences limit leads to very slow - compress times in which case a value of `20` or less is recommended. + `true` then the default `sequences` limit is `200`. Set option to `false` or `0` + to disable. The smallest `sequences` length is `2`. A `sequences` value of `1` + is grandfathered to be equivalent to `true` and as such means `200`. On rare + occasions the default sequences limit leads to very slow compress times in which + case a value of `20` or less is recommended. - `properties` -- rewrite property access using the dot notation, for example `foo["bar"] → foo.bar`