mishoo/UglifyJS — Issue #319: Cache property names, if nothing else
Author: qfox
Created: 2012-02-14 10:44:59+00:00
State: open

I see a bunch of tickets that might be related to this, but none that hit the mark. On top of that, uglifyjs currently simply doesn't do this even thought it's perfectly safe.

Just cache repetitive property names (but only if it turns out that this actually saves bytes).

``"foo".charCodeAt(2); "bar".charCodeAt(1);``

``var x='charCodeAt';"foo"[x](2);"bar"[x](1);``

I'm not aware of a single case where this breaks but the gains are huge. You basically have two ways of doing this; local and globally.

Local is safer in terms of speed. Fewer scope lookups make a happy engine. But if you define the caches globally, the gains have much more potential.

For an example, check out http://qfox.github.com/Zeon/console.html enter an example and press the minify button in the menu (top-left button). You can also disable this in the options to compare. Right now Zeon's minify kicks uglifyjs' butt and it shouldn't because Zeon basically only applies whitespace reduction, var name transformation and property name caching.