On 26 Mai, 11:23, Paul Bowsher <
paul.bows...@gmail.com> wrote:
> That's an interesting idea to use classes, but perhaps it would be better to
> work with jQuery / Prototype to make their selection engines better? Why are
> they able to find by classes so much quicker than by attributes?
> Paul Bowsher
I'm not absolutely sure about that. In the jQuery code there are a lot
of comments (regarding searching functionality) like:
// It's faster to filter by class and be done with it
or
// We can get a big speed boost by filtering by class here
I think, if they could make it faster, they would have tried
(because obviously they know that searching for classes
is currently a lot faster).
Unfortunately the jQuery source is generally hard to read,
so I don't know what they're exactly doing in the search/traversing
section. I've took a quick look at the prototype source, and
it seems that it's also easier for Prototype to find an element
by class.
But, maybe I'll prepare a full test for jQuery and Prototype
and checking this with several browsers. At least my above
jQuery sample with 5.000 elements runs a lot faster
on Safari (18ms for searching by class, 65ms for searching by
data-attribute).
But again: I think the Javascript experts (jQuery, Prototype, etc)
already did their best to make their code as fast as possible.:)