Changeset 106863 in webkit


Ignore:
Timestamp:
Feb 6, 2012 3:14:11 PM (12 years ago)
Author:
kling@webkit.org
Message:

REGRESSION(r106756): 10% performance hit on DOM/Template.
<http://webkit.org/b/77831>

Reviewed by Ryosuke Niwa.

Let the StylePropertySet used for element attribute style have the element as its parent.
This is accomplished by adding an m_parentIsElement bit to StylePropertySet and sharing
some of the internal logic with inline styles.

In the end, this means that CSSParser will now pick up the document's CSSValuePool when
parsing properties for attribute styles, which fixes the perf regression from r106756.

  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::StylePropertySet):
(WebCore::StylePropertySet::contextStyleSheet):

Find contextStyleSheet via the parentElement() when there is one.

(WebCore::StylePropertySet::setNeedsStyleRecalc):

Always set FullStyleChange for attribute style mutations. We can probably use the
same lighter invalidation as inline styles, but that's a topic for another patch.

  • css/StylePropertySet.h:

(WebCore::StylePropertySet::createInline):
(WebCore::StylePropertySet::createAttributeStyle):
(WebCore::StylePropertySet::parentRuleInternal):
(WebCore::StylePropertySet::clearParentRule):
(StylePropertySet):
(WebCore::StylePropertySet::parentElement):
(WebCore::StylePropertySet::clearParentElement):

Added m_parentIsElement bit and update assertions as appropriate to not just
cover the inline style case. Added a createAttributeStyle() helper to create
a StylePropertySet for use as Element::attributeStyle().

  • dom/StyledElement.h:
  • dom/ElementAttributeData.h:
  • dom/ElementAttributeData.cpp:

(WebCore::ElementAttributeData::ensureAttributeStyle):

Use StylePropertySet::createAttributeStyle().

  • dom/StyledElement.cpp:

(WebCore::StyledElement::removeCSSProperties):
(WebCore::StyledElement::addCSSProperty):
(WebCore::StyledElement::addCSSImageProperty):

Remove setNeedsStyleRecalc() calls since that is now handled automatically by
StylePropertySet's mutation methods.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106862 r106863  
     12012-02-06  Andreas Kling  <awesomekling@apple.com>
     2
     3        REGRESSION(r106756): 10% performance hit on DOM/Template.
     4        <http://webkit.org/b/77831>
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Let the StylePropertySet used for element attribute style have the element as its parent.
     9        This is accomplished by adding an m_parentIsElement bit to StylePropertySet and sharing
     10        some of the internal logic with inline styles.
     11
     12        In the end, this means that CSSParser will now pick up the document's CSSValuePool when
     13        parsing properties for attribute styles, which fixes the perf regression from r106756.
     14
     15        * css/StylePropertySet.cpp:
     16        (WebCore::StylePropertySet::StylePropertySet):
     17        (WebCore::StylePropertySet::contextStyleSheet):
     18
     19            Find contextStyleSheet via the parentElement() when there is one.
     20
     21        (WebCore::StylePropertySet::setNeedsStyleRecalc):
     22
     23            Always set FullStyleChange for attribute style mutations. We can probably use the
     24            same lighter invalidation as inline styles, but that's a topic for another patch.
     25
     26        * css/StylePropertySet.h:
     27        (WebCore::StylePropertySet::createInline):
     28        (WebCore::StylePropertySet::createAttributeStyle):
     29        (WebCore::StylePropertySet::parentRuleInternal):
     30        (WebCore::StylePropertySet::clearParentRule):
     31        (StylePropertySet):
     32        (WebCore::StylePropertySet::parentElement):
     33        (WebCore::StylePropertySet::clearParentElement):
     34
     35            Added m_parentIsElement bit and update assertions as appropriate to not just
     36            cover the inline style case. Added a createAttributeStyle() helper to create
     37            a StylePropertySet for use as Element::attributeStyle().
     38
     39        * dom/StyledElement.h:
     40        * dom/ElementAttributeData.h:
     41        * dom/ElementAttributeData.cpp:
     42        (WebCore::ElementAttributeData::ensureAttributeStyle):
     43
     44            Use StylePropertySet::createAttributeStyle().
     45
     46        * dom/StyledElement.cpp:
     47        (WebCore::StyledElement::removeCSSProperties):
     48        (WebCore::StyledElement::addCSSProperty):
     49        (WebCore::StyledElement::addCSSImageProperty):
     50
     51            Remove setNeedsStyleRecalc() calls since that is now handled automatically by
     52            StylePropertySet's mutation methods.
     53
    1542012-02-06  Kentaro Hara  <haraken@chromium.org>
    255
  • trunk/Source/WebCore/css/StylePropertySet.cpp

    r106695 r106863  
    170170StylePropertySet::StylePropertySet()
    171171    : m_strictParsing(false)
     172    , m_parentIsElement(false)
    172173    , m_isInlineStyleDeclaration(false)
    173174    , m_parent(static_cast<CSSRule*>(0))
     
    177178StylePropertySet::StylePropertySet(CSSRule* parentRule)
    178179    : m_strictParsing(!parentRule || parentRule->useStrictParsing())
     180    , m_parentIsElement(false)
    179181    , m_isInlineStyleDeclaration(false)
    180182    , m_parent(parentRule)
     
    185187    : m_properties(properties)
    186188    , m_strictParsing(!parentRule || parentRule->useStrictParsing())
     189    , m_parentIsElement(false)
    187190    , m_isInlineStyleDeclaration(false)
    188191    , m_parent(parentRule)
     
    193196StylePropertySet::StylePropertySet(CSSRule* parentRule, const CSSProperty* const * properties, int numProperties)
    194197    : m_strictParsing(!parentRule || parentRule->useStrictParsing())
     198    , m_parentIsElement(false)
    195199    , m_isInlineStyleDeclaration(false)
    196200    , m_parent(parentRule)
     
    215219}
    216220
    217 StylePropertySet::StylePropertySet(StyledElement* parentElement)
     221StylePropertySet::StylePropertySet(StyledElement* parentElement, bool isInlineStyle)
    218222    : m_strictParsing(false)
    219     , m_isInlineStyleDeclaration(true)
     223    , m_parentIsElement(true)
     224    , m_isInlineStyleDeclaration(isInlineStyle)
    220225    , m_parent(parentElement)
    221 { 
     226{
    222227}
    223228
     
    240245CSSStyleSheet* StylePropertySet::contextStyleSheet() const
    241246{
    242     if (m_isInlineStyleDeclaration) {
     247    if (m_parentIsElement) {
    243248        Document* document = m_parent.element ? m_parent.element->document() : 0;
    244249        return document ? document->elementSheet() : 0;
     
    706711void StylePropertySet::setNeedsStyleRecalc()
    707712{
    708     if (isInlineStyleDeclaration()) {
     713    if (m_parentIsElement) {
    709714        StyledElement* element = parentElement();
    710715        if (!element)
    711716            return;
     717
     718        if (!m_isInlineStyleDeclaration) {
     719            element->setNeedsStyleRecalc();
     720            return;
     721        }
     722
    712723        element->setNeedsStyleRecalc(InlineStyleChange);
    713724        element->invalidateStyleAttribute();
  • trunk/Source/WebCore/css/StylePropertySet.h

    r106695 r106863  
    5656    }
    5757    static PassRefPtr<StylePropertySet> createInline(StyledElement* element)
    58     {
    59         return adoptRef(new StylePropertySet(element));
     58    {
     59        return adoptRef(new StylePropertySet(element, /*isInlineStyle*/ true));
     60    }
     61    static PassRefPtr<StylePropertySet> createAttributeStyle(StyledElement* element)
     62    {
     63        return adoptRef(new StylePropertySet(element, /*isInlineStyle*/ false));
    6064    }
    6165
     
    110114    PassRefPtr<StylePropertySet> copyPropertiesInSet(const int* set, unsigned length) const;
    111115
    112     CSSRule* parentRuleInternal() const { return m_isInlineStyleDeclaration ? 0 : m_parent.rule; }
    113     void clearParentRule() { ASSERT(!m_isInlineStyleDeclaration); m_parent.rule = 0; }
    114    
    115     StyledElement* parentElement() const { ASSERT(m_isInlineStyleDeclaration); return m_parent.element; }
    116     void clearParentElement() { ASSERT(m_isInlineStyleDeclaration); m_parent.element = 0; }
    117    
     116    CSSRule* parentRuleInternal() const { return m_parentIsElement ? 0 : m_parent.rule; }
     117    void clearParentRule() { ASSERT(!m_parentIsElement); m_parent.rule = 0; }
     118
     119    StyledElement* parentElement() const { ASSERT(m_parentIsElement); return m_parent.element; }
     120    void clearParentElement() { ASSERT(m_parentIsElement); m_parent.element = 0; }
     121
    118122    CSSStyleSheet* contextStyleSheet() const;
    119123   
     
    127131    StylePropertySet(CSSRule* parentRule, const Vector<CSSProperty>&);
    128132    StylePropertySet(CSSRule* parentRule, const CSSProperty* const *, int numProperties);
    129     StylePropertySet(StyledElement*);
     133    StylePropertySet(StyledElement*, bool isInlineStyle);
    130134
    131135    void setNeedsStyleRecalc();
     
    156160
    157161    bool m_strictParsing : 1;
     162    bool m_parentIsElement : 1;
    158163    bool m_isInlineStyleDeclaration : 1;
    159164
  • trunk/Source/WebCore/dom/ElementAttributeData.cpp

    r106819 r106863  
    5454}
    5555
    56 StylePropertySet* ElementAttributeData::ensureAttributeStyle()
     56StylePropertySet* ElementAttributeData::ensureAttributeStyle(StyledElement* element)
    5757{
    58     if (!m_attributeStyle) {
    59         m_attributeStyle = StylePropertySet::create();
    60         m_attributeStyle->setStrictParsing(false);
    61     }
     58    if (!m_attributeStyle)
     59        m_attributeStyle = StylePropertySet::createAttributeStyle(element);
    6260    return m_attributeStyle.get();
    6361}
  • trunk/Source/WebCore/dom/ElementAttributeData.h

    r106819 r106863  
    4848
    4949    StylePropertySet* attributeStyle() const { return m_attributeStyle.get(); }
    50     StylePropertySet* ensureAttributeStyle();
     50    StylePropertySet* ensureAttributeStyle(StyledElement*);
    5151
    5252private:
  • trunk/Source/WebCore/dom/StyledElement.cpp

    r106769 r106863  
    111111        return;
    112112
    113     setNeedsStyleRecalc(FullStyleChange);
    114 
    115113    ASSERT(id1 != CSSPropertyInvalid);
    116114    style->removeProperty(id1);
     
    143141    if (!ensureAttributeStyle()->setProperty(id, value))
    144142        removeCSSProperty(id);
    145     else
    146         setNeedsStyleRecalc(FullStyleChange);
    147143}
    148144
     
    150146{
    151147    ensureAttributeStyle()->setProperty(id, value);
    152     setNeedsStyleRecalc(FullStyleChange);
    153148}
    154149
     
    156151{
    157152    ensureAttributeStyle()->setProperty(CSSProperty(id, CSSImageValue::create(url)));
    158     setNeedsStyleRecalc(FullStyleChange);
    159153}
    160154
  • trunk/Source/WebCore/dom/StyledElement.h

    r106819 r106863  
    5353
    5454    StylePropertySet* attributeStyle() const { return attributeData() ? attributeData()->attributeStyle() : 0; }
    55     StylePropertySet* ensureAttributeStyle() { return ensureAttributeData()->ensureAttributeStyle(); }
     55    StylePropertySet* ensureAttributeStyle() { return ensureAttributeData()->ensureAttributeStyle(this); }
    5656
    5757    const SpaceSplitString& classNames() const;
Note: See TracChangeset for help on using the changeset viewer.