Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: e5380247bac696f9220484a8947d4302bda6204f
https://github.com/WebKit/WebKit/commit/e5380247bac696f9220484a8947d4302bda6204f
Author: Antti Koivisto <[email protected]>
Date: 2026-04-20 (Mon, 20 Apr 2026)
Changed paths:
A LayoutTests/fast/selectors/has-invalidation-traversal-size-expected.txt
A LayoutTests/fast/selectors/has-invalidation-traversal-size.html
M Source/WebCore/css/parser/CSSSelectorParser.cpp
M Source/WebCore/css/parser/CSSSelectorParser.h
M Source/WebCore/dom/Document.h
M Source/WebCore/style/RuleFeature.cpp
M Source/WebCore/style/RuleFeature.h
M Source/WebCore/style/StyleInvalidator.cpp
M Source/WebCore/style/StyleInvalidator.h
M Source/WebCore/testing/Internals.cpp
M Source/WebCore/testing/Internals.h
M Source/WebCore/testing/Internals.idl
Log Message:
-----------
[:has() perf] Include full selector context to :has() invalidation selectors
https://bugs.webkit.org/show_bug.cgi?id=312786
rdar://175177078
Reviewed by Alan Baradlay.
When there is a mutation that may affect :has() we run the selector in has
argument to see if any of the
added or removed elements match. Previously this was done with the argument as
is. For
.foo:has(.bar) .baz
the invalidation selector was
<has-scope> .bar
where <has-scope> would always match. Any appearance of .bar would trigger
invalidation traversal.
With this patch we include the full context to invalidation selector so in
above case it will be
.foo .bar
potentially ruling out many cases where .bar alone matches.
Test: fast/selectors/has-invalidation-traversal-size.html
Document some traversal sizes.
* LayoutTests/fast/selectors/has-invalidation-traversal-size-expected.txt:
Added.
* LayoutTests/fast/selectors/has-invalidation-traversal-size.html: Added.
* Source/WebCore/css/parser/CSSSelectorParser.cpp:
(WebCore::CSSSelectorParser::makeHasArgumentReplacingScope):
Add helper for resolving <has-scope>.
* Source/WebCore/css/parser/CSSSelectorParser.h:
* Source/WebCore/dom/Document.h:
(WebCore::Document::styleInvalidationTraversalCountForTesting const):
(WebCore::Document::incrementStyleInvalidationTraversalCountForTesting):
(WebCore::Document::resetStyleInvalidationTraversalCountForTesting):
* Source/WebCore/style/RuleFeature.cpp:
(WebCore::Style::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):
(WebCore::Style::RuleFeatureSet::collectFeatures):
Resolve the scope.
* Source/WebCore/style/RuleFeature.h:
* Source/WebCore/style/StyleInvalidator.cpp:
(WebCore::Style::Invalidator::invalidateIfNeeded):
(WebCore::Style::Invalidator::invalidateWithMatchElementRuleSets):
* Source/WebCore/style/StyleInvalidator.h:
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::styleInvalidationTraversalCount const):
(WebCore::Internals::resetStyleInvalidationTraversalCount):
Add testing support
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:
Canonical link: https://commits.webkit.org/311642@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications