-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-selectors] :has()
and performance
#3345
Comments
I'm not an implementer so I don't know how valuable my comments on this should be considered, but I don't think that it is evaluation of the selector that is particularly hard, but rather the fact that it changes the subject and what tests need to be run on which things and when are different and don't fit neatly into existing strategies for avoiding a ton of extra work. That said, I do think there are probably limitations in what you could write and new optimizations that could strike a doable balance. |
That is not true. |
What @bkardell points out is also a problem, too, since that means that changes to an element can now affect the styles of arbitrary ancestors, and computing which ancestors are affected is not quite trivial. |
Even with that I don't think it'd be acceptable perf-wise. Parallelism only gives you a linear speedup with the number of cores best-case, while evaluating :has is exponential. |
(previous comment which I removed because I didn’t feel like it added anything valuable to the discussion)
That’s from JavaScript. I primarily meant the initial parsing, which ends up being fast‑ish since once you encounter |
That's not true either. The way style engines work is per-element. You build a list of all the rules on the page that match a certain element, for which you effectively need to do the work |
I'm going to point to this thread, where Boris Zbarsky has already answered this question in detail: We would all love for this to be performantly solved, and I'm sure it's possible with some kind of sophisticated caching and/or crazy inversion of the existing matching engines, but until someone actually does it and the other implementers agree to also take it on as a priority, it can't go in the spec, which is supposed to reflect an agreement of what should be imminently implemented. |
https://drafts.csswg.org/selectors-4/#profiles
The CSS selectors specification claims that
:has()
can’t be optimised, which isn’t accurate, as when:has()
is the last component of a selector (with no nested:has()
pseudo-classes), then:and
would be essentially identical in terms of performance, and therefore viable for the live profile.
The text was updated successfully, but these errors were encountered: