⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267582 in webkit


Ignore:
Timestamp:
Sep 25, 2020, 11:20:55 AM (6 years ago)
Author:
Alan Coon
Message:

Cherry-pick r266689. rdar://problem/69382883

[MotionMark - Multiply] Web process spends ~1% of total samples in PropertyCascade::resolveDirectionAndWritingMode
https://bugs.webkit.org/show_bug.cgi?id=216223

Reviewed by Darin Adler.

A few subtests in MotionMark (Leaves, Focus, Design, and especially Multiply) spend large amounts of time in
style resolution (Document::resolveStyle) due to constant style changes across many elements during every
frame. In Multiply, ~3-4% of the time underneath Document::resolveStyle is spent resolving direction and
writing modes inside PropertyCascade::resolveDirectionAndWritingMode (i.e., ~2.3 million invocations). This
helper function is responsible for computing the text direction and CSS writing mode that is used to resolve
direction-aware CSS properties (which are enumerated in CSSProperty::isDirectionAwareProperty). Resolving the
direction and writing mode involves iterating over all of the matched CSS properties (m_matchResult) in the
property cascade in search of CSS properties for writing and direction, which can be relatively expensive when
there are lots of properties in the cascade.

However, if there are no direction-aware CSS properties in the cascade, this work can actually be elided; to
achieve this, we can store the inherited Direction in m_direction, and then lazily resolve it if needed.

I measured this locally to yield a little under ~1% in the Multiply subtest in MotionMark. Otherwise, there is
no change in behavior; see below for more details.

  • style/PropertyCascade.cpp: (WebCore::Style::PropertyCascade::PropertyCascade): (WebCore::Style::PropertyCascade::set):

If we encounter a direction-aware CSS property, then use direction() to ensure that the direction and writing
mode are resolved.

(WebCore::Style::PropertyCascade::direction const):

Make this getter call resolveDirectionAndWritingMode if needed.

  • style/PropertyCascade.h:

Add a new bool member to keep track of whether or not the CSS direction has not yet been resolved. Note that
since this member variable fits within the padding after Direction m_direction;, this class is still the same
size.

(WebCore::Style::PropertyCascade::direction const): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266689 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-610-branch/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-610-branch/Source/WebCore/ChangeLog

    r267581 r267582  
     12020-09-22  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r266689. rdar://problem/69382883
     4
     5    [MotionMark - Multiply] Web process spends ~1% of total samples in PropertyCascade::resolveDirectionAndWritingMode
     6    https://bugs.webkit.org/show_bug.cgi?id=216223
     7   
     8    Reviewed by Darin Adler.
     9   
     10    A few subtests in MotionMark (Leaves, Focus, Design, and especially Multiply) spend large amounts of time in
     11    style resolution (`Document::resolveStyle`) due to constant style changes across many elements during every
     12    frame. In Multiply, ~3-4% of the time underneath `Document::resolveStyle` is spent resolving direction and
     13    writing modes inside `PropertyCascade::resolveDirectionAndWritingMode` (i.e., ~2.3 million invocations). This
     14    helper function is responsible for computing the text direction and CSS writing mode that is used to resolve
     15    direction-aware CSS properties (which are enumerated in `CSSProperty::isDirectionAwareProperty`). Resolving the
     16    direction and writing mode involves iterating over all of the matched CSS properties (`m_matchResult`) in the
     17    property cascade in search of CSS properties for writing and direction, which can be relatively expensive when
     18    there are lots of properties in the cascade.
     19   
     20    However, if there are no direction-aware CSS properties in the cascade, this work can actually be elided; to
     21    achieve this, we can store the inherited `Direction` in `m_direction`, and then lazily resolve it if needed.
     22   
     23    I measured this locally to yield a little under ~1% in the Multiply subtest in MotionMark. Otherwise, there is
     24    no change in behavior; see below for more details.
     25   
     26    * style/PropertyCascade.cpp:
     27    (WebCore::Style::PropertyCascade::PropertyCascade):
     28    (WebCore::Style::PropertyCascade::set):
     29   
     30    If we encounter a direction-aware CSS property, then use `direction()` to ensure that the direction and writing
     31    mode are resolved.
     32   
     33    (WebCore::Style::PropertyCascade::direction const):
     34   
     35    Make this getter call `resolveDirectionAndWritingMode` if needed.
     36   
     37    * style/PropertyCascade.h:
     38   
     39    Add a new `bool` member to keep track of whether or not the CSS direction has not yet been resolved. Note that
     40    since this member variable fits within the padding after `Direction m_direction;`, this class is still the same
     41    size.
     42   
     43    (WebCore::Style::PropertyCascade::direction const): Deleted.
     44   
     45   
     46    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     47
     48    2020-09-06  Wenson Hsieh  <wenson_hsieh@apple.com>
     49
     50            [MotionMark - Multiply] Web process spends ~1% of total samples in PropertyCascade::resolveDirectionAndWritingMode
     51            https://bugs.webkit.org/show_bug.cgi?id=216223
     52
     53            Reviewed by Darin Adler.
     54
     55            A few subtests in MotionMark (Leaves, Focus, Design, and especially Multiply) spend large amounts of time in
     56            style resolution (`Document::resolveStyle`) due to constant style changes across many elements during every
     57            frame. In Multiply, ~3-4% of the time underneath `Document::resolveStyle` is spent resolving direction and
     58            writing modes inside `PropertyCascade::resolveDirectionAndWritingMode` (i.e., ~2.3 million invocations). This
     59            helper function is responsible for computing the text direction and CSS writing mode that is used to resolve
     60            direction-aware CSS properties (which are enumerated in `CSSProperty::isDirectionAwareProperty`). Resolving the
     61            direction and writing mode involves iterating over all of the matched CSS properties (`m_matchResult`) in the
     62            property cascade in search of CSS properties for writing and direction, which can be relatively expensive when
     63            there are lots of properties in the cascade.
     64
     65            However, if there are no direction-aware CSS properties in the cascade, this work can actually be elided; to
     66            achieve this, we can store the inherited `Direction` in `m_direction`, and then lazily resolve it if needed.
     67
     68            I measured this locally to yield a little under ~1% in the Multiply subtest in MotionMark. Otherwise, there is
     69            no change in behavior; see below for more details.
     70
     71            * style/PropertyCascade.cpp:
     72            (WebCore::Style::PropertyCascade::PropertyCascade):
     73            (WebCore::Style::PropertyCascade::set):
     74
     75            If we encounter a direction-aware CSS property, then use `direction()` to ensure that the direction and writing
     76            mode are resolved.
     77
     78            (WebCore::Style::PropertyCascade::direction const):
     79
     80            Make this getter call `resolveDirectionAndWritingMode` if needed.
     81
     82            * style/PropertyCascade.h:
     83
     84            Add a new `bool` member to keep track of whether or not the CSS direction has not yet been resolved. Note that
     85            since this member variable fits within the padding after `Direction m_direction;`, this class is still the same
     86            size.
     87
     88            (WebCore::Style::PropertyCascade::direction const): Deleted.
     89
    1902020-09-22  Alan Coon  <alancoon@apple.com>
    291
  • branches/safari-610-branch/Source/WebCore/style/PropertyCascade.cpp

    r262922 r267582  
    149149    : m_matchResult(matchResult)
    150150    , m_includedProperties(includedProperties)
    151     , m_direction(resolveDirectionAndWritingMode(direction))
     151    , m_direction(direction)
    152152{
    153153    buildCascade(cascadeLevels);
     
    157157    : m_matchResult(parent.m_matchResult)
    158158    , m_includedProperties(parent.m_includedProperties)
    159     , m_direction(parent.m_direction)
     159    , m_direction(parent.direction())
     160    , m_directionIsUnresolved(false)
    160161{
    161162    buildCascade(cascadeLevels);
     
    197198void PropertyCascade::set(CSSPropertyID id, CSSValue& cssValue, unsigned linkMatchType, CascadeLevel cascadeLevel, ScopeOrdinal styleScopeOrdinal)
    198199{
    199     if (CSSProperty::isDirectionAwareProperty(id))
    200         id = CSSProperty::resolveDirectionAwareProperty(id, m_direction.textDirection, m_direction.writingMode);
     200    if (CSSProperty::isDirectionAwareProperty(id)) {
     201        auto direction = this->direction();
     202        id = CSSProperty::resolveDirectionAwareProperty(id, direction.textDirection, direction.writingMode);
     203    }
    201204
    202205    ASSERT(!shouldApplyPropertyInParseOrder(id));
     
    405408}
    406409
    407 }
    408 }
     410PropertyCascade::Direction PropertyCascade::direction() const
     411{
     412    if (m_directionIsUnresolved) {
     413        m_direction = resolveDirectionAndWritingMode(m_direction);
     414        m_directionIsUnresolved = false;
     415    }
     416    return m_direction;
     417}
     418
     419}
     420}
  • branches/safari-610-branch/Source/WebCore/style/PropertyCascade.h

    r252313 r267582  
    6868    const HashMap<AtomString, Property>& customProperties() const { return m_customProperties; }
    6969
    70     Direction direction() const { return m_direction; }
     70    Direction direction() const;
    7171
    7272    const PropertyCascade* propertyCascadeForRollback(CascadeLevel) const;
     
    8686    const MatchResult& m_matchResult;
    8787    const IncludedProperties m_includedProperties;
    88     const Direction m_direction;
     88    mutable Direction m_direction;
     89    mutable bool m_directionIsUnresolved { true };
    8990
    9091    Property m_properties[numCSSProperties + 2];
Note: See TracChangeset for help on using the changeset viewer.