Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Slow performance with ":not(:has())" #428
I was working with a complicated and slow selector on a site that is taking more than 7 seconds to return an empty set. The selector I was using is
The first interesting thing about it is that are no matching
The second thing I noticed is that older versions of Sizzle seem to run this a lot faster, and I pinpointed the problem to the fixes done on b948c8a, so I'm thinking that it may have something to do with the way that cache is stored. The issue is not happening on Sizzle 1.10.15, where the selector even on first runs takes less than 500ms. Reverting those changes improves the speed dramatically (although I understand this may reintroduce some bugs).
I tried my hand at fixing this, with no luck, as to be honest, I don't understand much of that code and what it's doing.
I understand that the selector is pretty non-standard and makes sense for it to be slow, but it shouldn't be reaching even one second I think.
Hi @lomegor, thank you for the report. Selector engine tuning is complicated, as you've seen in the Sizzle codebase, and there are always tradeoffs. We currently process every complex selector right-to-left (i.e., establishing a candidate set and then checking for ancestors/preceding siblings that match earlier compound selectors), and then process the simple selectors of each compound selector right-to-left as well (on the assumption that the rightmost ones will be the most specific and therefore winnow out undesired elements at the earliest point).
In this case, that means testing