Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Heya felix. It actually IS possible to get several times faster than jQuery in microbenchmarks on specific implementations when you can hit the native version for a path or something your interpreter knows how to optimize. As an example, I did an optimzing pass through underscore.js specifically for node.js, mostly swapping in native calls and switching loops to the idiomatic for(var i =0, ii=x.length, i < ii, i++) since V8 knows how to optimize those. The result is a several times speedup. Native methods are faster than javascript ones. This shouldn't be surprising.

Despite the work being done for node, I wanted to see how it looked on the various browser engines, so I made a pasted together set of screenshots [1] showing the underscore benchmark suite running in Chrome, Firefox 3.5, and a recent Minefield nightly. Results are paired underscore before my tweaks and after.

[1] http://gr.ayre.st/s/images/underscore_perf_benches.gif

I believe the methods all have the same signatures and are operating on the same set of data. jQuery has the disadvantage here of having to work on a variety of interpreters where I only care about v8. The interesting bit is to note the jQuery.map() call on the newer tracemonkey is FASTER than using my for loop. It all depends on what the interpreter can optimize and hitting those paths. I have notes [2] on my optimizations if you're interested in how the various approaches bench on node. I was going for low hanging fruit, so these were done with a simple timing function on the node repl.

[2] http://wiki.github.com/grayrest/underscore/node-conversion-i...



Interesting! I've been using underscore myself, great stuff! Are you going to maintain your fork in the future?

As far as getting faster than jQuery goes, I agree with what you're saying. What is difficult is getting faster in a "meaningful" way - everything else seems like a waste of time to me.


We've also pulled a bunch of grayrest's excellent patches back into Underscore -- the ones that work cross-browser. The latest 0.5.1 version of Underscore includes them.


> Are you going to maintain your fork in the future?

I've been working on building a library like Narwhal's. This fork of underscore is my util.js equivalent.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: