Wednesday, June 28th, 2006
Speeding up Prototype’s $$ Selector
Sylvain Zimmer has written a performance upgrade for Prototype’s $$ function that he claims is up to twenty times faster.
Sylvain’s ideas behind the patch are as follows:
- Forwarding the call to the old $$ if the selector expression is too complicated (currently : if it uses attributes)
- Replacing regular expressions with a simple parser
- Minimizing the number of operations done on each iteration.
- Trying to use getDocumentById() instead of getDocumentByTagName() when possible.
- Avoiding recursive functions with return values.
- Not being afraid of some “old-style” code if it speeds up the execution ;-)
Now, lets see if Sam applies it…












Thanks a lot for the mention!
Remember, my patch is open for discussion, I’d appreciate any feedback that can improve it ;-)
(BTW, I think there is a typo in the title? SpeeDing ;p)
Thanks again!
Heh, yep fixed the typo.
NICE! I need this bad!
[...] I was ecstatic when I found (via Ajaxian) that Sylvain Zimmer has sped up the $$ function quite a bit. I implemented it in the test area of MasterWish and have been very pleased with the results! Here’s what Sylvain has to say on his mod: Prototype’s current code is quite elegant (as always!) but very slow, so I wrote an add-on that makes this function up to 20 times faster in most usual cases (tested on IE6, Firefox 1.5 and Opera). [...]
Liming,
Your bottleneck when doing web programmingis generally not disk access — it is the network. For example, accessing my router is a 2 ms roundtrip. My hard drive seek-time is measured in nanoseconds. A profiler would reveal that you most likely do not need this.
Hasan: I’m no expert but I don’t think this optimization involves disk seeks as the page is most often in the ram. I think it’s more a CPU-related thing, but I could be wrong.
cheers
[...] Ajaxian Prototype The Prototype Window Class allows you to add in-browser windows with the flick of a few … Terry Laurenzo found that he liked “the simplicity of Prototype, … [...]
@Hasan:
Yeah, imagine… someone is actually trying to optimize performance. Who would be that foolish? I mean, when I pull down a ton of data via ajax, THAT is the only thing I worry about… who cares about processing it as fast as possible once it hits the browser.
Sheesh…