4 ms·
Might some of these little idiomatic optimizations be automatically performed by the Closure Compiler, making their absence from the original source irrelevant?
by gojomo 17y ago
Might some of these little idiomatic optimizations be automatically performed by the Closure Compiler, making their absence from the original source irrelevant?
- qeorge 17y agoPerhaps, 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. :)
- nostrademons 17y agoClosure 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.
- asher 17y agoThat was my first thought. I ran the "slow loop" through the online compiler at: http://closure-compiler.appspot.com/home 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.
- jeff18 17y agoIt would have to determine that arr.length doesn't change during the loop. Pretty difficult problem. :)
- gojomo 17y agoI'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: http://en.wikipedia.org/wiki/Loop-invariant_code_motion http://en.wikipedia.org/wiki/Loop-invariant_code_motion