I was attempting to optimize a plugin that needs to extract a lot of data from the DOM. When testing in IE9, I found it to be agonizingly slow when I used the jQuery text() method. I soon discovered that going straight for the textContent showed significant improvement.
I looked through the core and it looks like the text method creates a new node before extracting the text... it's all very convoluted to me, so I may be interpreting that wrong. I did find two instances of textContent being used though, in the "evalScript" function and in the "contains" filter. Wouldn't the text method benefit from this change as well?
I understand that the text method will never be as fast as the direct method, but when I threw together a
jsPerf test (it's my first, so I may have done it wrong) it looks like jQuery is about 600x slower than textContent, in Firefox. I added a MooTools test for reference and even it performs about 90x faster in Firefox than jQuery.
So, can we take another look at these methods and see if there is a way to improve them? Or at least tell me if my interpretation is wrong.
Thanks!
Rob