Changeset 107173 in webkit


Ignore:
Timestamp:
Feb 8, 2012 8:41:19 PM (12 years ago)
Author:
kling@webkit.org
Message:

Increased style sharing for elements with presentation attributes.
<http://webkit.org/b/78199>

Reviewed by Antti Koivisto.

When determining whether two elements can share style, we can do a lot better.
Instead of comparing the attribute maps for exact equality, do a property-by-property
comparison of the attributeStyle() and the additionalAttributeStyle() (if any.)

This increases our style sharing hit rate and shaves 100ms off of each cycle on
Chromium's "Moz" page cycler test on my machine.

The function that compares attribute styles has O(n2) runtime in the worst case,
where n is the number of properties in the styles. However, given the low number of
properties found in attribute styles, this should be fine, and it doesn't seem to
heat up in profiles.

  • css/CSSStyleSelector.cpp:

(WebCore::attributeStylesEqual):
(WebCore::CSSStyleSelector::canShareStyleWithElement):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107172 r107173  
     12012-02-08  Andreas Kling  <awesomekling@apple.com>
     2
     3        Increased style sharing for elements with presentation attributes.
     4        <http://webkit.org/b/78199>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        When determining whether two elements can share style, we can do a lot better.
     9        Instead of comparing the attribute maps for exact equality, do a property-by-property
     10        comparison of the attributeStyle() and the additionalAttributeStyle() (if any.)
     11
     12        This increases our style sharing hit rate and shaves 100ms off of each cycle on
     13        Chromium's "Moz" page cycler test on my machine.
     14
     15        The function that compares attribute styles has O(n^2) runtime in the worst case,
     16        where n is the number of properties in the styles. However, given the low number of
     17        properties found in attribute styles, this should be fine, and it doesn't seem to
     18        heat up in profiles.
     19
     20        * css/CSSStyleSelector.cpp:
     21        (WebCore::attributeStylesEqual):
     22        (WebCore::CSSStyleSelector::canShareStyleWithElement):
     23
    1242012-02-08  Raymond Liu  <raymond.liu@intel.com>
    225
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r107162 r107173  
    11951195}
    11961196
     1197// This function makes some assumptions that only make sense for attribute styles (we only compare CSSProperty::id() and CSSProperty::value().)
     1198static inline bool attributeStylesEqual(StylePropertySet* a, StylePropertySet* b)
     1199{
     1200    if (a == b)
     1201        return true;
     1202    if (a->propertyCount() != b->propertyCount())
     1203        return false;
     1204    unsigned propertyCount = a->propertyCount();
     1205    for (unsigned i = 0; i < propertyCount; ++i) {
     1206        const CSSProperty& aProperty = a->propertyAt(i);
     1207        unsigned j;
     1208        for (j = 0; j < propertyCount; ++j) {
     1209            const CSSProperty& bProperty = b->propertyAt(j);
     1210            if (aProperty.id() != bProperty.id())
     1211                continue;
     1212            // We could get a few more hits by comparing cssText() here, but that gets expensive quickly.
     1213            if (aProperty.value() != bProperty.value())
     1214                return false;
     1215            break;
     1216        }
     1217        if (j == propertyCount)
     1218            return false;
     1219    }
     1220    return true;
     1221}
     1222
    11971223bool CSSStyleSelector::canShareStyleWithElement(StyledElement* element) const
    11981224{
     
    12101236        return false;
    12111237    if (!!element->attributeStyle() != !!m_styledElement->attributeStyle())
     1238        return false;
     1239    StylePropertySet* additionalAttributeStyleA = element->additionalAttributeStyle().get();
     1240    StylePropertySet* additionalAttributeStyleB = m_styledElement->additionalAttributeStyle().get();
     1241    if (!additionalAttributeStyleA != !additionalAttributeStyleB)
    12121242        return false;
    12131243    if (element->isLink() != m_element->isLink())
     
    12751305        return false;
    12761306
    1277     if (element->attributeStyle() && !element->attributeMap()->mapsEquivalent(m_styledElement->attributeMap()))
     1307    if (element->attributeStyle() && !attributeStylesEqual(element->attributeStyle(), m_styledElement->attributeStyle()))
     1308        return false;
     1309
     1310    if (additionalAttributeStyleA && !attributeStylesEqual(additionalAttributeStyleA, additionalAttributeStyleB))
    12781311        return false;
    12791312
Note: See TracChangeset for help on using the changeset viewer.