Settings

Theme

Demystifying jQuery selector optimization

no-margin-for-errors.com

4 points by brown9 17 years ago · 4 comments

Reader

pfisch 17 years ago

This is not really accurate information. The methodology is poor compared to other selector tests, and the results are less accurate and less specific. Selector optimization changes based upon the browser. The slowest browsers(ie6) actually select faster with $(tagname.classname) and other more specific selectors. Of course he didn't mention which browsers he tested in or which version of jquery or if it was an average of many runs.

In anycase it is probably more worthwhile to optimize for the slowest browsers that you want to be compatible with, and those browsers are not firefox unless you don't care about like half of the people on the internet.

edit - just to clarify, based upon his results I'm guessing he's only using firefox to run these tests.

  • brown9OP 17 years ago

    (I think the author of the blog post was a "she")

    Do you have some links to other selector optimization tests/benchmarks/posts? I'd be interested in seeing those as well

  • ironkeith 17 years ago

    It doesn't feel like an overly comprehensive test to me either. He also doesn't mention how many test cycles he's running, browser versions, etc.

geuis 17 years ago

I don't know if it helps, but I talked to John Resig last Friday night after day 1 of JSConf2009. I specifically was asking about how Sizzle works when selecting. The jist of it is that Sizzle selects the maximum number of possible elements, then pairs them down until it finds the ones you are looking for. I haven't dugg back into the Sizzle code yet to really see how this is being done, but it might help others who are curious.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection