News for hackers. Stuff that matters.
Re:JavaScript Performance MythBusters (via jsPerf) by dspillett on Saturday March 17, 2012 @07:54AM (#3716866)
> Some of the tests they link prove the opposite of what they say in the slides.

The content can't be seen without signing in and it would appear that I've forgotten the password for my fake-details account, so I can't look at the code specifically.

But I can say that it is not unexpected that the results one person gets can diverge significantly when someone else tries the same test. A lot of code rearrangements that are intended to speed up Javascript execution are optimised for a particular browser (or, if people are being more thorough, a particular subset of browsers). What is optimal for Firefox's engine is not necessarily so for Chrome's, and performance metrics can vary significantly between different versions of the same browser as changes are made to optimisations within the code interpreter/compiler over time. Heck, even exactly the same version of Firefox may behave differently performance-wise on Linux than Windows.

You can never say that a given "trick" is an optimisation generally because there are many variables. Unless of course what you are actually doing is optimising your logic rather than rearranging it (i.e. changing from something that is akin to a linear search to something that has a logarithmic growth pattern) but that isn't optimising Javascript, it is optimising the algorithm you've implemented using the language.

> Also, saying that eval is not evil is evil.

There are very specific circumstances when eval() can be used with relative safety [i.e. when the only injection method is by direct code manipulation, and all client-side Javascript is susceptible to that with or without eval()]. Other than that I agree, and none of the cases where eval() is safe that spring to mind can't be implemented some other way (at least in modern browsers).

Re:JavaScript Performance MythBusters (via jsPerf) by ghusbands on Saturday March 17, 2012 @08:22AM (#3716903)
While you're entirely correct that results can differ between browers, many of the links are to jsperf, which compensates for test-run variance and shows a comparative graph of all results; some of those graphs demonstrate the opposite of what the linking slides say.

For an example, they link to http://jsperf.com/undefined-void0-perf to show that using void 0 instead of undefined is not a performance win. The data shows there's no browser in which void 0 is slower than undefined and several browsers in which is it faster, by as much as 50-60%.

Re:JavaScript Performance MythBusters (via jsPerf) by jdd on Saturday March 17, 2012 @03:01PM (#3717862)
You're right that there isn't a real perf win as each are millions of ops/sec vs more-millions and not likely to matter in real world use.
Re:JavaScript Performance MythBusters (via jsPerf) by gcb on Saturday March 17, 2012 @09:19PM (#3718777)
Real world usage is relative.

In my real world case a change in loop mattered a lot for ie6 users (60% of our use base at the time, sadly). It was .5sec that we couldn't get from other means.

Re:JavaScript Performance MythBusters (via jsPerf) by jdd on Saturday March 17, 2012 @09:31PM (#3718804)
I doubt millions vs more-millions of ops/sec is ever going to be a real problem for anyone as engines are only getting faster.

I've never heard someone say "Oh yeah, the bottleneck in our app was our use of `==`".

The loops slides were more about modern engines not IE6 :P

I've had mandated IE6 support before, and still support it in my personal JS libs, so I feel your pain.