Title: [134664] trunk/Source/WebCore
Revision
134664
Author
[email protected]
Date
2012-11-14 13:58:13 -0800 (Wed, 14 Nov 2012)

Log Message

Only resolve presentation attribute style once per shared ElementAttributeData.
<http://webkit.org/b/100990>

Reviewed by Antti Koivisto.

Track the "presentation attribute style dirty" state on ElementAttributeData instead of in a Node flag.
This allows us to avoid duplicate work for ElementAttributeData that are shared between multiple elements,
since the state is no longer per-Element.

I've left the presentation attribute cache in there for now, since it still covers the case where
two elements have the same presentation attributes but different non-presentation attributes.
It's likely that we're not gaining much from it anymore, but that's a topic for another patch.

(WebCore::StyledElement::rebuildPresentationAttributeStyle):
* dom/StyledElement.h:
(WebCore::StyledElement::presentationAttributeStyle):
(WebCore::ElementAttributeData::ElementAttributeData):
* dom/ElementAttributeData.h:
(WebCore::ElementAttributeData::ElementAttributeData):
(ElementAttributeData):
* dom/Node.h:

    Move presentation attribute style dirty flag from Node to ElementAttributeData.

* dom/ElementAttributeData.cpp:
(SameSizeAsElementAttributeData):

    Add a compile-time object size assertion for ElementAttributeData.

* dom/StyledElement.cpp:
(WebCore::StyledElement::attributeChanged):

    Don't mark the presentation attribute style dirty if the element is using an immutable (implies
    shared) ElementAttributeData and another element has already generated the StylePropertySet.
    The element itself is still marked for style recalc like before, this just avoids the process
    of converting the attributes to CSS properties.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (134663 => 134664)


--- trunk/Source/WebCore/ChangeLog	2012-11-14 21:56:19 UTC (rev 134663)
+++ trunk/Source/WebCore/ChangeLog	2012-11-14 21:58:13 UTC (rev 134664)
@@ -1,3 +1,42 @@
+2012-11-14  Andreas Kling  <[email protected]>
+
+        Only resolve presentation attribute style once per shared ElementAttributeData.
+        <http://webkit.org/b/100990>
+
+        Reviewed by Antti Koivisto.
+
+        Track the "presentation attribute style dirty" state on ElementAttributeData instead of in a Node flag.
+        This allows us to avoid duplicate work for ElementAttributeData that are shared between multiple elements,
+        since the state is no longer per-Element.
+
+        I've left the presentation attribute cache in there for now, since it still covers the case where
+        two elements have the same presentation attributes but different non-presentation attributes.
+        It's likely that we're not gaining much from it anymore, but that's a topic for another patch.
+
+        (WebCore::StyledElement::rebuildPresentationAttributeStyle):
+        * dom/StyledElement.h:
+        (WebCore::StyledElement::presentationAttributeStyle):
+        (WebCore::ElementAttributeData::ElementAttributeData):
+        * dom/ElementAttributeData.h:
+        (WebCore::ElementAttributeData::ElementAttributeData):
+        (ElementAttributeData):
+        * dom/Node.h:
+
+            Move presentation attribute style dirty flag from Node to ElementAttributeData.
+
+        * dom/ElementAttributeData.cpp:
+        (SameSizeAsElementAttributeData):
+
+            Add a compile-time object size assertion for ElementAttributeData.
+
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::attributeChanged):
+
+            Don't mark the presentation attribute style dirty if the element is using an immutable (implies
+            shared) ElementAttributeData and another element has already generated the StylePropertySet.
+            The element itself is still marked for style recalc like before, this just avoids the process
+            of converting the attributes to CSS properties.
+
 2012-11-14  Scott Violet  <[email protected]>
 
         [Chromium] Refactor theme font lookup into a factory

Modified: trunk/Source/WebCore/dom/ElementAttributeData.cpp (134663 => 134664)


--- trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-11-14 21:56:19 UTC (rev 134663)
+++ trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-11-14 21:58:13 UTC (rev 134664)
@@ -31,6 +31,13 @@
 
 namespace WebCore {
 
+struct SameSizeAsElementAttributeData : public RefCounted<SameSizeAsElementAttributeData> {
+    unsigned bitfield;
+    void* refPtrs[4];
+};
+
+COMPILE_ASSERT(sizeof(ElementAttributeData) == sizeof(ElementAttributeData), element_attribute_data_should_stay_small);
+
 static size_t sizeForImmutableElementAttributeDataWithAttributeCount(unsigned count)
 {
     return sizeof(ImmutableElementAttributeData) - sizeof(void*) + sizeof(Attribute) * count;
@@ -75,6 +82,7 @@
 ElementAttributeData::ElementAttributeData(const ElementAttributeData& other, bool isMutable)
     : m_isMutable(isMutable)
     , m_arraySize(isMutable ? 0 : other.length())
+    , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDirty)
     , m_presentationAttributeStyle(other.m_presentationAttributeStyle)
     , m_classNames(other.m_classNames)
     , m_idForStyleResolution(other.m_idForStyleResolution)

Modified: trunk/Source/WebCore/dom/ElementAttributeData.h (134663 => 134664)


--- trunk/Source/WebCore/dom/ElementAttributeData.h	2012-11-14 21:56:19 UTC (rev 134663)
+++ trunk/Source/WebCore/dom/ElementAttributeData.h	2012-11-14 21:58:13 UTC (rev 134664)
@@ -88,17 +88,20 @@
     ElementAttributeData()
         : m_isMutable(true)
         , m_arraySize(0)
+        , m_presentationAttributeStyleIsDirty(false)
     { }
 
     ElementAttributeData(unsigned arraySize)
         : m_isMutable(false)
         , m_arraySize(arraySize)
+        , m_presentationAttributeStyleIsDirty(false)
     { }
 
     ElementAttributeData(const ElementAttributeData&, bool isMutable);
 
     unsigned m_isMutable : 1;
-    unsigned m_arraySize : 31;
+    unsigned m_arraySize : 30;
+    mutable unsigned m_presentationAttributeStyleIsDirty : 1;
 
     mutable RefPtr<StylePropertySet> m_inlineStyle;
     mutable RefPtr<StylePropertySet> m_presentationAttributeStyle;

Modified: trunk/Source/WebCore/dom/Node.h (134663 => 134664)


--- trunk/Source/WebCore/dom/Node.h	2012-11-14 21:56:19 UTC (rev 134663)
+++ trunk/Source/WebCore/dom/Node.h	2012-11-14 21:58:13 UTC (rev 134664)
@@ -319,7 +319,6 @@
     virtual void notifyLoadedSheetAndAllCriticalSubresources(bool /* error loading subresource */) { }
     virtual void startLoadingDynamicSheet() { ASSERT_NOT_REACHED(); }
 
-    bool attributeStyleDirty() const { return getFlag(PresentationAttributeStyleDirtyFlag); }
     bool hasName() const { return getFlag(HasNameFlag); }
     bool hasID() const;
     bool hasClass() const;
@@ -335,9 +334,6 @@
     bool childNeedsStyleRecalc() const { return getFlag(ChildNeedsStyleRecalcFlag); }
     bool isLink() const { return getFlag(IsLinkFlag); }
 
-    void setPresentationAttributeStyleDirty() { setFlag(PresentationAttributeStyleDirtyFlag); }
-    void clearPresentationAttributeStyleDirty() { clearFlag(PresentationAttributeStyleDirtyFlag); }
-
     void setHasName(bool f) { setFlag(f, HasNameFlag); }
     void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
     void clearChildNeedsStyleRecalc() { clearFlag(ChildNeedsStyleRecalcFlag); }
@@ -726,22 +722,21 @@
 
         HasNameFlag = 1 << 23,
 
-        PresentationAttributeStyleDirtyFlag = 1 << 24,
+        InNamedFlowFlag = 1 << 24,
+        HasSyntheticAttrChildNodesFlag = 1 << 25,
+        HasCustomCallbacksFlag = 1 << 26,
+        HasScopedHTMLStyleChildFlag = 1 << 27,
+        HasEventTargetDataFlag = 1 << 28,
+        InEdenFlag = 1 << 29,
 
 #if ENABLE(SVG)
         DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag | AreSVGAttributesValidFlag,
 #else
         DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag,
 #endif
-        InNamedFlowFlag = 1 << 26,
-        HasSyntheticAttrChildNodesFlag = 1 << 27,
-        HasCustomCallbacksFlag = 1 << 28,
-        HasScopedHTMLStyleChildFlag = 1 << 29,
-        HasEventTargetDataFlag = 1 << 30,
-        InEdenFlag = 1 << 31
     };
 
-    // 1 bit remaining
+    // 2 bits remaining
 
     bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
     void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); } 

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (134663 => 134664)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2012-11-14 21:56:19 UTC (rev 134663)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2012-11-14 21:58:13 UTC (rev 134664)
@@ -163,7 +163,9 @@
 void StyledElement::attributeChanged(const QualifiedName& name, const AtomicString& newValue)
 {
     if (isPresentationAttribute(name)) {
-        setPresentationAttributeStyleDirty();
+        // Avoid dirtying the presentation attribute style if we're using shared attribute data with already generated style.
+        if (attributeData()->isMutable() || !attributeData()->m_presentationAttributeStyle)
+            attributeData()->m_presentationAttributeStyleIsDirty = true;
         setNeedsStyleRecalc(InlineStyleChange);
     }
 
@@ -338,8 +340,8 @@
             collectStyleForPresentationAttribute(*attribute, style.get());
         }
     }
-    clearPresentationAttributeStyleDirty();
 
+    attributeData()->m_presentationAttributeStyleIsDirty = false;
     attributeData()->setPresentationAttributeStyle(style->isEmpty() ? 0 : style);
 
     if (!cacheHash || cacheIterator->value)

Modified: trunk/Source/WebCore/dom/StyledElement.h (134663 => 134664)


--- trunk/Source/WebCore/dom/StyledElement.h	2012-11-14 21:56:19 UTC (rev 134663)
+++ trunk/Source/WebCore/dom/StyledElement.h	2012-11-14 21:58:13 UTC (rev 134664)
@@ -90,9 +90,11 @@
 
 inline const StylePropertySet* StyledElement::presentationAttributeStyle()
 {
-    if (attributeStyleDirty())
+    if (!attributeData())
+        return 0;
+    if (attributeData()->m_presentationAttributeStyleIsDirty)
         rebuildPresentationAttributeStyle();
-    return attributeData() ? attributeData()->presentationAttributeStyle() : 0;
+    return attributeData()->presentationAttributeStyle();
 }
 
 } //namespace
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to