Re:Google Closure: How not to write Javascript
by gojomo on Thursday November 12, 2009 @12:57AM
(#937231)
Might some of these little idiomatic optimizations be automatically performed by the Closure Compiler, making their absence from the original source irrelevant?
[ Parent
| on HN ]
Re:Google Closure: How not to write Javascript
by asher on Thursday November 12, 2009 @01:52AM
(#937289)
That was my first thought. I ran the "slow loop" through the online compiler at:
http://closure-compiler.appspot.com/home
And whether I checked "Simple" or "Advanced" I got:
for(var a = 0;a < arr.length;a++)
So it's not optimizing that pattern yet.
Re:Google Closure: How not to write Javascript
by jeff18 on Thursday November 12, 2009 @02:06AM
(#937315)
It would have to determine that arr.length doesn't change during the loop. Pretty difficult problem. :)
Re:Google Closure: How not to write Javascript
by gojomo on Thursday November 12, 2009 @12:46PM
(#938272)
I'm unsure if the smiley means you're being sarcastic, but if not:
Such determinations are a pretty common thing for an optimizing compiler to attempt:
Re:Google Closure: How not to write Javascript
by qeorge on Thursday November 12, 2009 @01:12AM
(#937244)
Perhaps, but it does seem that the Google Closure developers are unaware of these optimizations. Unless the compiler was written by an entirely different group, I would be surprised.
Of course, there's an easy way to find out. :)
Re:Google Closure: How not to write Javascript
by nostrademons on Thursday November 12, 2009 @01:25AM
(#937259)
Closure was written by many, many different people. I can attest that the core developers (the ones whose names are on the project) are very aware of these optimizations - one of them interviewed me when I was being hired, and another was in charge of my JS readability review. But Closure's a big chunk of code, though, and the core developers tend to be very busy people, and not everyone can review everything.