Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Descendent Attribute Selectors and Performance Re: Descendent Attribute Selectors and Performance

#135850
rob_edgar
Member

Thanks – I used jsPerf to test a few things out (should have done this first I guess).

Tested checking ‘body[data-xyz=”abc”] #abc{}’ from a depth of 500 nodes and again at 50 nodes.

There was little difference in performance which confirms that it must check the element first on each node.

Using just a straight access on the ‘#abc’ node for comparison, checking the attribute on the body was 70% slower.

So you can draw from this that walking the DOM tree is very fast and the ‘slowness’ is really just a factor of needing to access two nodes instead of one.

Oh and curiously using an attribute on the body was faster than a class on the body although the difference was trivial about 1%.

Rob