Sign in or Join FriendFeed
FriendFeed is the easiest way to share online. Learn more »
Joel Webber
Javascript Variables, Continued - http://blog.j15r.com/2009...
My previous post on this subject apparently offended some troll, for reasons I can't quite comprehend. If anyone has a spare moment, it would be great if they could have a look over this to make sure I'm not missing anything important. It's just in my nature, but trolls get under my skin, and I like to be *really* sure I'm right, and not dismissing legitimate concerns (however rudely expressed). - Joel Webber
My impression of the previous commenter was that he basically said "your results don't jive with my assumptions, so I'll quote the spec at you". The test page linked from the second page is 404ing for me though. - Matt Mastracci
Doing a search for Garrett Smith turns up several articles, Amazon reviews, and comments that are basically the same as what he posted on your site. It seems he's made it his life mission to tell everyone that they're wrong about JavaScript, but I haven't figured out where he gets that authority yet, though. Your article seemed reasonable, but I admit that I lack the knowledge base to provide constructive criticism on what you may or may not have gotten wrong. - Mark Trapp
Thanks, all. I really shouldn't let the trolls bug me, yet somehow they always do. @matt: whoops, thanks. Forgot to upload the file. Will fix that momentarily. - Joel Webber
Fixed. - Joel Webber
I think your methodology and tests are fine and test exactly what you are looking at. My Chrome numbers are surprising (closure sometimes beat locals!) but I wouldn't but it past the JIT. My only thought here would be that you could up the # of tests an order of magnitude to help remove some of the timer jitter. - Matt Mastracci
Yeah, I was surprised by the fact that closures sometimes beat locals on Chrome as well. But as you say, that JIT is pretty sneaky, so you never can tell. I may try bumping up the numbers at some point, but they don't jitter too badly averaging over 100 runs, so I'm guessing the variance isn't too high. If I weren't so lazy, I would set it up to calculate variance and confidence, but I *am* lazy :) - Joel Webber
Hah yeah. I don't get much in the way of jitter on OSX. Maybe I missed the high-resolution-timer revolution, but browsers seem way better at timing these days. In the past I'd only ever get 15ms resolution on setTimeout() or Date stuff. - Matt Mastracci
Interesting conclusion from your test: if you use a non-local more than twice (insert exact hand-wavy justification here), stuff it into a local. - Matt Mastracci
That's a really good point. In general, I suspect there's some crossover point where it becomes better to declare a local cache for multiply-referenced globals. The scary implication of some of these measurements is that you'd have to do browser-specific code generation to get optimal results. - Joel Webber