You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a Bublé-ism. Should be solved by #362 or one of the other bublé-->babel PR's.
I find it interesting though that Terser wouldn't have compressed the output to look like your final version. Perhaps it's avoiding assigning to arguments because it doesn't know the resulting code will be run in strict mode?
Perhaps it's avoiding assigning to arguments because it doesn't know the resulting code will be run in strict mode?
Maybe... What I find even more surprising though is the +=1 bit - that one should certainly be equivalent to ++ in any context and is sort of obvious for a minifier.
What I find even more surprising though is the +=1 bit - that one should certainly be equivalent to ++ in any context and is sort of obvious for a minifier.
Many have proposed it. Nothing is obvious in javascript.
@bmeurer@mathiasbynens On another topic, are there any JS engine performance implications of repurposing function parameters as local scratch variables instead of explicitly declaring local vars? The function parameters x and sum in the top post are an example of this.
I recall that Google Closure Compiler used to perform this sort of transform to reduce code size. Perhaps it still does.
If you declare additional parameters that are not passed at the call site, then you incur a small call overhead, since the engine has to (dynamically) pad the parameters with undefined. Whether or not that's worth the code size savings is up to you to decide.
Reacted by Marvin Hagemeister, Mathias Bynens and kzc
@kzc Doesn't the minifier already implement basic control flow checks for other optimisations? Although, in this particular case, I suppose it's easier to fix the transpiler side to produce ++ in the first place.
Doesn't the minifier already implement basic control flow checks for other optimisations?
The uglify derived minifiers presently implement a varied set of AST heuristics, often involving tree scanning, for specific tasks that collectively give the illusion of complete control flow analysis. There is no SSA or anything like that that'd be required for comprehensive type analysis. However, you can get a long way with specific directed optimizations. Take a look at the documentation for the compress options, or examine the code for more details.
At the end of the day, some optimizations are not worth doing if their occurrences in real life code are infrequent, or if minification payoff is negligible (particularly post gzip), or if the runtime analysis cost is prohibitively expensive. You also have to weigh the implementation complexity and the resultant maintenance issues for an open source project run by a couple of people in their spare time.
Activity
developit commentedon May 22, 2019
This is a Bublé-ism. Should be solved by #362 or one of the other bublé-->babel PR's.
I find it interesting though that Terser wouldn't have compressed the output to look like your final version. Perhaps it's avoiding assigning to arguments because it doesn't know the resulting code will be run in strict mode?
RReverser commentedon May 22, 2019
Maybe... What I find even more surprising though is the
+=1bit - that one should certainly be equivalent to++in any context and is sort of obvious for a minifier.kzc commentedon May 25, 2019
Many have proposed it. Nothing is obvious in javascript.
The minifier would need to implement control flow and type analysis to do that correctly.
marvinhagemeister commentedon May 27, 2019
FYI: asked this question on Twitter: https://twitter.com/marvinhagemeist/status/1133074844906606594
kzc commentedon May 27, 2019
@bmeurer @mathiasbynens On another topic, are there any JS engine performance implications of repurposing function parameters as local scratch variables instead of explicitly declaring local vars? The function parameters
xandsumin the top post are an example of this.I recall that Google Closure Compiler used to perform this sort of transform to reduce code size. Perhaps it still does.
bmeurer commentedon May 28, 2019
If you declare additional parameters that are not passed at the call site, then you incur a small call overhead, since the engine has to (dynamically) pad the parameters with
undefined. Whether or not that's worth the code size savings is up to you to decide.mathiasbynens commentedon May 28, 2019
More info: https://v8.dev/blog/v8-release-74#faster-calls-with-arguments-mismatch
RReverser commentedon May 28, 2019
@kzc Doesn't the minifier already implement basic control flow checks for other optimisations? Although, in this particular case, I suppose it's easier to fix the transpiler side to produce
++in the first place.kzc commentedon May 28, 2019
The uglify derived minifiers presently implement a varied set of AST heuristics, often involving tree scanning, for specific tasks that collectively give the illusion of complete control flow analysis. There is no SSA or anything like that that'd be required for comprehensive type analysis. However, you can get a long way with specific directed optimizations. Take a look at the documentation for the compress options, or examine the code for more details.
At the end of the day, some optimizations are not worth doing if their occurrences in real life code are infrequent, or if minification payoff is negligible (particularly post gzip), or if the runtime analysis cost is prohibitively expensive. You also have to weigh the implementation complexity and the resultant maintenance issues for an open source project run by a couple of people in their spare time.