closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Add option to disable string array literal peephole optimization

Open nazar-pc opened this issue 7 years ago • 3 comments

This was initially posted to mailing list, but no one replied, so here is the feature request.

I have AMD module with following line:

define(['@detox/crypto', '@detox/dht', '@detox/utils', 'ronion', 'fixed-size-multiplexer', 'async-eventer', 'pako'], Wrapper)

The issue is that starting with 6th depedency Closure Compiler in advanced mode decides that it is a good idea to replace that array with splitted string like this:

define("@detox/crypto @detox/dht @detox/utils ronion fixed-size-multiplexer async-eventer pako".split(" "),A)

Which makes sense in general, but fails when I try to use minified result with https://github.com/requirejs/r.js, which doesn't understand such construction and requires explicit array of dependencies.

It would be very useful to have an option to disable this particular optimization in advanced mode.

nazar-pc avatar May 29 '18 17:05 nazar-pc

There's another reason for considering a toggle: it might be responsible for some slowdown I'm experiencing: the ADVANCED version of my code, even with successful GCC inlining of some inner loop math functions and reduced code size, is noticeably slower than SIMPLE, and this is one difference I can think of. But who knows, maybe a .split(' ') is speed competitive with the browser's native tokenization and parsing of an array? 🤷‍♂

I noticed other weird things, eg. it uses an apparently random mix of fat arrows and functions while it'd be completely free to use fat arrows, as in my input code (not a this, class or arguments in sight). Also, inlining is hard to trigger, as if it only looked at the count of the use rather than a measurement of how much it adds to the code size (negative to negligible if one tries to inline short math operations). Maybe there could be some configurable number for inlining aggressiveness, and in general, levers for the code size vs runtime optimization goal.

monfera avatar May 22 '19 23:05 monfera

Created Google internal issue b/133453443.

tjgq avatar May 24 '19 00:05 tjgq

@tjgq bump on this - am having the same issue as @nazar-pc

jpcastberg avatar Nov 19 '21 22:11 jpcastberg