Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 245943e53c92260358ae98799c107126fa07a6ca
      
https://github.com/WebKit/WebKit/commit/245943e53c92260358ae98799c107126fa07a6ca
  Author: Antti Koivisto <[email protected]>
  Date:   2026-04-21 (Tue, 21 Apr 2026)

  Changed paths:
    M LayoutTests/fast/selectors/has-invalidation-traversal-size-expected.txt
    M LayoutTests/fast/selectors/has-invalidation-traversal-size.html
    M LayoutTests/platform/mac/TestExpectations
    M Source/WebCore/css/parser/CSSSelectorParser.cpp
    M Source/WebCore/css/parser/CSSSelectorParser.h
    M Source/WebCore/style/RuleFeature.cpp
    M Source/WebCore/style/RuleFeature.h
    M Source/WebCore/style/RuleSet.h
    M Source/WebCore/style/StyleInvalidator.cpp
    M Source/WebCore/style/StyleScopeRuleSets.cpp
    M Source/WebCore/style/StyleScopeRuleSets.h

  Log Message:
  -----------
  [:has() perf] Limit invalidation traversal with scope selector
https://bugs.webkit.org/show_bug.cgi?id=312866
rdar://175233639

Reviewed by Alan Baradlay.

For a selector like

.foo:has(.bar) .baz

we know that any potentially affected element for .bar change is in .foo 
subtree. By saving and using the
the scope selector (".foo" here) we can limit invalidation traversal to the 
minimal subtree.

* LayoutTests/fast/selectors/has-invalidation-traversal-size-expected.txt:
* LayoutTests/fast/selectors/has-invalidation-traversal-size.html:
* LayoutTests/platform/mac/TestExpectations:
* Source/WebCore/css/parser/CSSSelectorParser.cpp:
(WebCore::collectHasCompoundContext):
(WebCore::appendSelector):
(WebCore::buildScopeSelector):
(WebCore::CSSSelectorParser::makeHasScopeSelector):
(WebCore::CSSSelectorParser::makeHasArgumentWithScope):
(WebCore::CSSSelectorParser::makeHasArgumentReplacingScope): Deleted.
* Source/WebCore/css/parser/CSSSelectorParser.h:
* Source/WebCore/style/RuleFeature.cpp:
(WebCore::Style::RuleFeatureWithInvalidationSelector::RuleFeatureWithInvalidationSelector):
(WebCore::Style::RuleFeatureSet::collectFeatures):

Save the scope selector to RuleFeature.
Since we are passing the scope selector we don't need to resolve the 
invalidation selectors against the scope here,
we can do it at RuleSet building time.

* Source/WebCore/style/RuleFeature.h:
(WebCore::Style::RuleFeatureWithInvalidationSelector::RuleFeatureWithInvalidationSelector):
* Source/WebCore/style/RuleSet.h:
* Source/WebCore/style/StyleInvalidator.cpp:
(WebCore::Style::Invalidator::invalidateStyleWithMatchElement):

In Ancestor/Descendant case use the scope selector to find the scope element 
and traverse that subtree only.

(WebCore::Style::Invalidator::addToMatchElementRuleSets):
(WebCore::Style::Invalidator::addToMatchElementRuleSetsRespectingNegation):
* Source/WebCore/style/StyleScopeRuleSets.cpp:
(WebCore::Style::ensureInvalidationRuleSets):

Include the scope selector to InvalidationRuleSet.
Resolve the invalidation selector scopes.

* Source/WebCore/style/StyleScopeRuleSets.h:

Canonical link: https://commits.webkit.org/311702@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to