John David Dalton
Getify Solutions, Owner
Join Mathias Bynens and John-David Dalton from jsPerf.com, Chris Joel from Cloudflare.com and Lindsey Simon from Google/Browserscope in this panel discussion on some of the best dev-created benchmarks and most interesting practices debunked by real-world tests.
Browserscope and jsPerf
Open-source, community-driven project for profiling browsers. Really good at helping inform developers by providing number crunching and actual data. The whole idea is that anyone can reproduce results with any type of hardware (crowdsourcing).
- Foster innovation by tracking functionality
- Push browser innovation, uncover regressions
- Historical resource for web developers
- Your for loops suck: rewrite all your code and use: while –i BUSTED
- Double your localStorage read performances in Chrome by getting by index. TRUE
- The arguments object should be avoided. BUSTED (but isn’t as good in Opera)
- Frameworks (like jQuery) are always better at managing performance than you are, so just use what they provide. BUSTED
- Converting a NodeList to an array is expensive, so you shouldn’t do it. For instance document.getElementsByTagName() returns a NodeList, not an array, and then iterating over it compared to an array after taking the performance hit of converting it. BUSTED (also see: Static node list, which is closer to a performance with an array)
- Eval is evil, it’s too slow and quirky to be considered useful. BUSTED The performance is pretty much equal with all benchmarks.
- Regular expressions are slow and should be replaced with simple string method calls using indexOf(). BUSTED Engines are getting faster now with RegEx.
- OO API abstraction means you never have to worry about the details (including the performance). BUSTED Your API design matters more than it just being OO.
- Type torsion (===) takes more processing power than a regular comparison (==). BUSTED There is a difference, but it’s so tiny you shouldn’t be concerned.
- Caching “nested property lookup” or “prototype chain lookup” helps (or hurts) performance BUSTED In most cases the browser engine already makes the cache, and this wont matter at all
- Operations which require an implicit primitive-to-object cast/conversion will be slower BUSTED For instance, when converting a number to a toString() or toNumber() it doesn’t affect performance
- Scope chain lookups are expensive BUSTED
- Use switch statements instead of if/else if for better performance. POSSIBLY. In most cases this is true, except in Safari and Mobile Safari. The panel recommended to just use what you need.
- Use native methods for better performance. BUSTED