ender-js/ender-js — pull request #11 by rvagg (2012-01-02 04:52:09+00:00)
Title: use __proto__ in place of aug() where available

And now for something completely awesome...

Instead of doing a full property copy to element lists each time a call to `$()` is made, use `__proto__` to copy the whole prototype across in one go; leads to a **massive** speedup in browsers that support it (everything but IE).

`boosh` first needs to have `Array.prototype` attached to it so the returns still do everything arrays do, then you put `boosh` as the prototype of `els` (whatever it is!) and we get everything that's on `boosh` on `els`. So this works even if a property has been added via `$.fn`.

Here's the numbers: using just the Jeesh, doing a `$(element)` we get:

* 740% faster in Firefox (Aurora, Linux)
* 3,800% faster in Chrome (Beta, Linux)
* 2,150% faster in Opera (Windows)
* 1,200% faster in Safari (Windows)

And that's **just the Jeesh**! For every package you add you have more properties to copy with `aug()` and I bet most Ender builds have more than just the Jeesh.

Benchmarks can be run here in whatever browser you like: http://rvagg.github.com/ender-js/benchmarks/index.html (2 frames, top one has a standard Ender build, the bottom has the modified version using `__proto__`).

I'm using this in production on a large project of mine (with Jeesh + a ton of other packages) without any problems.