views:

124

answers:

2

The company I work at bought us (or rather me) the jQuery Cookbook by O'Reilly which I am reading from front to back. Now I am at 5.13 which talks about Name Lookups. It claims that given the right circumstances, code which is optimized regarding Name Lookups can have an up to 70% performance boost. In one very situational example, it claims to be even 35x faster and cutting execution time from 7 seconds to a mere 0.2 seconds!

My Question is: By which factor does a Name Lookup Optimization enhance performance in a real live situation an is it worth the extra few hours on a 4k JS-lines AJAX Application?

+3  A: 

The factor which it helps depends on how it is used really. Its like asking how long is a piece of string.

I have seen setting names for true,false, undefined can make an application at least 10x faster in the javascript. The reason why it become faster is that it doesn't need to look inside the global scope chain. Nick Zakas explains it quite well in the video below from google code

http://googlecode.blogspot.com/2009/06/nicholas-c-zakas-speed-up-your.html

EDIT:

I just came across this and thought it may be useful. its a quick explanation of the scoping chain too. http://www.phpied.com/extreme-javascript-optimization/

AutomatedTester
+2  A: 

Nicholas Zakas did some researches on the subject and talks about this on this Google Tech Talk. It seems that you can get an interesting performance enhancement. I'm not sure about the exact number, but the sure thing is that optimizing name lookups will improve the speed of your code.

Of course if you're dragging 10 years of legacy code behind you that is working just fine, don't worry about optimizing... but if your application is slow, I'd consider optimizing the code.

If you decide to go with refactoring, try to pinpoint what you can optimize. I recommend using the the javascript profiler of firebug to do so.

You can even try optimizing a minor part of your code, see the performance boost that you get and then figure out if it's worth optimizing the rest of your app.

marcgg
I am optimizing Code I wrote some months ago when I just started with JavaScript and jQuery. I had no Experience with it whatsoever so I am learning quite a bit from the techniques described in the book
Mike
Then it could be a good exercice for you to go back and refactor your code. You'll see how much you progressed... and of course you'll hate your old code ^^
marcgg
I'm hating it already :P
Mike