John-David Dalton - Perf the web forward
JSConf US 2013
31 May 2013Talking about how to improve existing libraries and your own code with some performance gains techniques. John-David is the creator of jsperf.com
Themes
optimize for the common case use natives wisely - array foreach, filter, map, etc vs for loops etc as alternatives avoid abstraction - reduce function calls, etc balance pros/cons
Hoist call & apply
(dojo, ember, jquery, prime, underscore would all benefit) from: while loop { callback.call(values) } to: callback = createCallback() < - do this outside the loop, createCallback returns callback.call then do callback(values) within loop
Avoid binding
By detecting “this” use if not using this, don’t bind
Reduce searches
indexOf is searching through entire array, large arrays therefore slower if test on property (obj[key] exists?) that’s better but integer 2 == string “2” so unique operations will fail cache parts of large arrays in to smaller arrays for searching (applies to underscore, possibly jquery - these would benefit)
Coerce with care
arguments - don’t need to slice, can apply it instead of underscore’s flatten (or homegrown) you can concat (native) - use Array.prototype as the this argument no need to create new
array.push can accept more than one argument
Sugar in moderation
chaining API has performance cost in some libs, generic api in others - be aware of fast/slow paths
lazy.js - http://dtao.github.io/lazy.js very performant in chaining
twitter: @jdalton
www: jsperf.com
www: lodash.com (underscore alternative)
www: benchmarkjs.com
hashtag for this talk: #perffwd
JSConf 2013
This is a quick summary of a talk I attended at JSConf 2013. You can see a list of all those I've summarized notes from here. There's also a General thoughts during JSConf 2013 post for all the non-talk bits and pieces.
There were 3 concurrent tracks at the conference, so only those I attended myself are summarized here. Other attendees have summarized some of the talks I didn't get to due to scheduling conflicts - you can find those at jlongster.com (James Long) and Toby Ho's github repo.