Avoid resolving style for elements that only inherit changes from parent
commit96d20b24a8c1f0334f5530b9f1feb598cfd56bfe
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 May 2022 07:12:20 +0000 (8 07:12 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 May 2022 07:12:20 +0000 (8 07:12 +0000)
tree3512bed1274029991024fe52ff827768c219138f
parente253a70b89d83cd2e1e30abddc57cd8862d52a38
Avoid resolving style for elements that only inherit changes from parent
https://bugs.webkit.org/show_bug.cgi?id=240132
<rdar://problem/92867346>

Reviewed by Sam Weinig.

Source/WebCore:

When an inherited property changes we need to update all descendant styles too. Currently this
is done by simply running the full style resolution for them including selector matching and
style building steps.

In the common case nothing changes in descendants expect the inherited properties. This patch implements
a fast-path mechanism that allows us to simply copy the relevant properties from the parent, skipping
all the other work. This is possible if we can prove that the value of these properties is not changed
by any rules targeting the child and that there are no other properties affected by this value change.

The mechanism is only implemented for the 'color' property for now. It can be expanded for other properties later.
It would be especially useful for custom properties.

* css/CSSProperties.json:
* css/makeprop.pl:

Add "fast-path-inherited" codegen property that disables the fast-path if the property is explicitly mutated.

(generateInitialValueSetter):
(generateValueSetter):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::RenderStyle):
(WebCore::RenderStyle::fastPathInheritFrom):

Inherit fast path properties.

(WebCore::RenderStyle::fastPathInheritedEqual const):
(WebCore::RenderStyle::nonFastPathInheritedEqual const):

Test for fast-path property changes.

* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::disallowsFastPathInheritance const):
(WebCore::RenderStyle::setDisallowsFastPathInheritance):

Track if can use the mechanism.

(WebCore::RenderStyle::NonInheritedFlags::operator== const):
* rendering/style/StyleInheritedData.cpp:
(WebCore::StyleInheritedData::operator== const):
(WebCore::StyleInheritedData::fastPathInheritedEqual const):
(WebCore::StyleInheritedData::nonFastPathInheritedEqual const):
(WebCore::StyleInheritedData::fastPathInheritFrom):
* rendering/style/StyleInheritedData.h:
* style/StyleBuilderCustom.h:
(WebCore::Style::BuilderCustom::applyValueFill):
(WebCore::Style::BuilderCustom::applyValueStroke):
* style/StyleBuilderState.cpp:
(WebCore::Style::BuilderState::colorFromPrimitiveValueWithResolvedCurrentColor const):

Color value 'currentcolor' is mostly resolved during use time but in the few places we still resolve it during style building
we need to disable the fast-path, since it makes other properties depend on 'color' property.

* style/StyleChange.cpp:
(WebCore::Style::determineChange):

New style change type for fast-path inheritance.

* style/StyleChange.h:
* style/StyleTreeResolver.cpp:
(WebCore::Style::TreeResolver::styleForStyleable):

Resolve by just copying properties from the parent.

(WebCore::Style::TreeResolver::computeDescendantsToResolve):
(WebCore::Style::TreeResolver::resolveElement):
(WebCore::Style::TreeResolver::determineResolutionType):

Use fast-path if the only reason we are resolving this element is that some supported inherited property changed.

(WebCore::Style::TreeResolver::resolveComposedTree):
(WebCore::Style::TreeResolver::shouldResolveElement): Deleted.
* style/StyleTreeResolver.h:

Tools:

* Scripts/webkitpy/style/checkers/jsonchecker.py:
(JSONCSSPropertiesChecker.check_codegen_properties):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@293956 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSProperties.json
Source/WebCore/css/makeprop.pl
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/StyleInheritedData.cpp
Source/WebCore/rendering/style/StyleInheritedData.h
Source/WebCore/style/StyleBuilderCustom.h
Source/WebCore/style/StyleBuilderState.cpp
Source/WebCore/style/StyleChange.cpp
Source/WebCore/style/StyleChange.h
Source/WebCore/style/StyleTreeResolver.cpp
Source/WebCore/style/StyleTreeResolver.h
Tools/ChangeLog
Tools/Scripts/webkitpy/style/checkers/jsonchecker.py