[webkit-changes] [WebKit/WebKit] 9b67f9: REGRESSION(268038 at main): poor performance with :ha...

Antti Koivisto noreply at github.com
Thu Jan 4 23:59:38 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9b67f95c4810d05d68b047eb9e84b48f7826783d
      https://github.com/WebKit/WebKit/commit/9b67f95c4810d05d68b047eb9e84b48f7826783d
  Author: Antti Koivisto <antti at apple.com>
  Date:   2024-01-04 (Thu, 04 Jan 2024)

  Changed paths:
    M Source/WebCore/css/SelectorChecker.cpp
    M Source/WebCore/dom/Element.cpp
    M Source/WebCore/dom/Element.h
    M Source/WebCore/dom/Node.cpp
    M Source/WebCore/dom/Node.h
    M Source/WebCore/style/ChildChangeInvalidation.cpp
    M Source/WebCore/style/ChildChangeInvalidation.h
    M Source/WebCore/style/RuleFeature.cpp
    M Source/WebCore/style/StyleRelations.cpp
    M Source/WebCore/style/StyleRelations.h

  Log Message:
  -----------
  REGRESSION(268038 at main): poor performance with :has(+ :not(.class)) pseudo-class selector
https://bugs.webkit.org/show_bug.cgi?id=267078
rdar://119819247

Reviewed by Cameron McCormack.

The selector gets misclassified as scope breaking.
Fixing the issue reveals it was hiding other invalidation bugs.

* Source/WebCore/css/SelectorChecker.cpp:
(WebCore::SelectorChecker::matchHasPseudoClass const):

Add a new flag for the case where element is affected by :has() containing :nth-child() and similar.
The use of existing flags didn't work correctly in all situations because they would get wiped at
wrong time.

* Source/WebCore/dom/Element.cpp:
(WebCore::Element::resetStyleRelations):
* Source/WebCore/dom/Element.h:
(WebCore::Element::affectedByHasWithPositionalPseudoClass const):
(WebCore::Element::setAffectedByHasWithPositionalPseudoClass):
* Source/WebCore/dom/Node.cpp:
(WebCore::Node::adjustStyleValidity):
* Source/WebCore/dom/Node.h:
(WebCore::Node::hasInvalidRenderer const):
(WebCore::Node::setHasValidStyle):

Juggle the flags around to make space.

* Source/WebCore/style/ChildChangeInvalidation.cpp:
(WebCore::Style::ChildChangeInvalidation::invalidateForHasBeforeMutation):
(WebCore::Style::ChildChangeInvalidation::invalidateForHasAfterMutation):

Handle text node insertions and removals since they may affect :empty state within :has().
Test for the new :nth-child() flag instead of the old ones.

* Source/WebCore/style/ChildChangeInvalidation.h:
(WebCore::Style::ChildChangeInvalidation::ChildChangeInvalidation):
* Source/WebCore/style/RuleFeature.cpp:
(WebCore::Style::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):

Break out of the loop if the current selector is the leftmost one before computing
MatchElement/IsScopeBreaking. Selector :not(.class) would get computed as scope breaking
even though there is nothing on the left of .class. Also stop CanBreakScope::Yes from affecting
subsequent selectors after the one that can actually leak the scope.

* Source/WebCore/style/StyleRelations.cpp:
(WebCore::Style::commitRelationsToRenderStyle):
(WebCore::Style::commitRelations):
* Source/WebCore/style/StyleRelations.h:

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




More information about the webkit-changes mailing list