Title: [135939] trunk/Source/WebCore
Revision
135939
Author
akl...@apple.com
Date
2012-11-27 16:34:19 -0800 (Tue, 27 Nov 2012)

Log Message

Shrink ShadowRoot and TreeScope.
<http://webkit.org/b/103459>

Reviewed by Antti Koivisto.

We're creating ~1500 ShadowRoots on Apple's PLT3 content (from <input> and <textarea> elements)
and a lot of this is wasted space.

Shrink ShadowRoot and TreeScope a bit by making TreeScope's DocumentOrderedMaps heap-allocated
and packing the counters on ShadowRoot harder together with the bits.

202kB progression on Membuster3.

* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::ShadowRoot):
* dom/ShadowRoot.h:
(WebCore::ShadowRoot::countElementShadow):
(ShadowRoot):
* dom/TreeScope.cpp:
(WebCore::TreeScope::TreeScope):
(WebCore::TreeScope::getElementById):
(WebCore::TreeScope::addElementById):
(WebCore::TreeScope::removeElementById):
(WebCore::TreeScope::addImageMap):
(WebCore::TreeScope::removeImageMap):
(WebCore::TreeScope::getImageMap):
(WebCore::TreeScope::addLabel):
(WebCore::TreeScope::removeLabel):
(WebCore::TreeScope::labelElementForId):
* dom/TreeScope.h:
(WebCore::TreeScope::shouldCacheLabelsByForAttribute):
(TreeScope):
(WebCore::TreeScope::hasElementWithId):
(WebCore::TreeScope::containsMultipleElementsWithId):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135938 => 135939)


--- trunk/Source/WebCore/ChangeLog	2012-11-28 00:24:25 UTC (rev 135938)
+++ trunk/Source/WebCore/ChangeLog	2012-11-28 00:34:19 UTC (rev 135939)
@@ -1,3 +1,40 @@
+2012-11-27  Andreas Kling  <akl...@apple.com>
+
+        Shrink ShadowRoot and TreeScope.
+        <http://webkit.org/b/103459>
+
+        Reviewed by Antti Koivisto.
+
+        We're creating ~1500 ShadowRoots on Apple's PLT3 content (from <input> and <textarea> elements)
+        and a lot of this is wasted space.
+
+        Shrink ShadowRoot and TreeScope a bit by making TreeScope's DocumentOrderedMaps heap-allocated
+        and packing the counters on ShadowRoot harder together with the bits.
+
+        202kB progression on Membuster3.
+
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::ShadowRoot):
+        * dom/ShadowRoot.h:
+        (WebCore::ShadowRoot::countElementShadow):
+        (ShadowRoot):
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::TreeScope):
+        (WebCore::TreeScope::getElementById):
+        (WebCore::TreeScope::addElementById):
+        (WebCore::TreeScope::removeElementById):
+        (WebCore::TreeScope::addImageMap):
+        (WebCore::TreeScope::removeImageMap):
+        (WebCore::TreeScope::getImageMap):
+        (WebCore::TreeScope::addLabel):
+        (WebCore::TreeScope::removeLabel):
+        (WebCore::TreeScope::labelElementForId):
+        * dom/TreeScope.h:
+        (WebCore::TreeScope::shouldCacheLabelsByForAttribute):
+        (TreeScope):
+        (WebCore::TreeScope::hasElementWithId):
+        (WebCore::TreeScope::containsMultipleElementsWithId):
+
 2012-11-14  Jer Noble  <jer.no...@apple.com>
 
         Add a new shared class WebCoreFullScreenWarningView which presents a styled warning message.

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (135938 => 135939)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-11-28 00:24:25 UTC (rev 135938)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-11-28 00:34:19 UTC (rev 135939)
@@ -60,14 +60,14 @@
     , TreeScope(this)
     , m_prev(0)
     , m_next(0)
-    , m_applyAuthorStyles(false)
-    , m_resetStyleInheritance(false)
-    , m_registeredWithParentShadowRoot(false)
     , m_insertionPointAssignedTo(0)
     , m_numberOfShadowElementChildren(0)
     , m_numberOfContentElementChildren(0)
     , m_numberOfElementShadowChildren(0)
     , m_numberOfStyles(0)
+    , m_applyAuthorStyles(false)
+    , m_resetStyleInheritance(false)
+    , m_registeredWithParentShadowRoot(false)
 {
     ASSERT(document);
     

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (135938 => 135939)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2012-11-28 00:24:25 UTC (rev 135938)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2012-11-28 00:34:19 UTC (rev 135939)
@@ -101,7 +101,7 @@
     void registerElementShadow() { ++m_numberOfElementShadowChildren; }
     void unregisterElementShadow() { ASSERT(hasElementShadow()); --m_numberOfElementShadowChildren; }
     bool hasElementShadow() const { return m_numberOfElementShadowChildren > 0; }
-    size_t countElementShadow() const { return m_numberOfElementShadowChildren; }
+    unsigned countElementShadow() const { return m_numberOfElementShadowChildren; }
 
     virtual void registerScopedHTMLStyleChild() OVERRIDE;
     virtual void unregisterScopedHTMLStyleChild() OVERRIDE;
@@ -125,15 +125,15 @@
 
     ShadowRoot* m_prev;
     ShadowRoot* m_next;
-    bool m_applyAuthorStyles : 1;
-    bool m_resetStyleInheritance : 1;
-    bool m_isAuthorShadowRoot : 1;
-    bool m_registeredWithParentShadowRoot : 1;
     InsertionPoint* m_insertionPointAssignedTo;
-    size_t m_numberOfShadowElementChildren;
-    size_t m_numberOfContentElementChildren;
-    size_t m_numberOfElementShadowChildren;
-    size_t m_numberOfStyles;
+    unsigned m_numberOfShadowElementChildren;
+    unsigned m_numberOfContentElementChildren;
+    unsigned m_numberOfElementShadowChildren;
+    unsigned m_numberOfStyles : 28;
+    unsigned m_applyAuthorStyles : 1;
+    unsigned m_resetStyleInheritance : 1;
+    unsigned m_isAuthorShadowRoot : 1;
+    unsigned m_registeredWithParentShadowRoot : 1;
 };
 
 inline Element* ShadowRoot::host() const

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (135938 => 135939)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2012-11-28 00:24:25 UTC (rev 135938)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2012-11-28 00:34:19 UTC (rev 135939)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All Rights Reserved.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -56,7 +57,6 @@
 TreeScope::TreeScope(ContainerNode* rootNode)
     : m_rootNode(rootNode)
     , m_parentTreeScope(0)
-    , m_shouldCacheLabelsByForAttribute(false)
     , m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
 {
     ASSERT(rootNode);
@@ -91,18 +91,24 @@
 {
     if (elementId.isEmpty())
         return 0;
-    return m_elementsById.getElementById(elementId.impl(), this);
+    if (!m_elementsById)
+        return 0;
+    return m_elementsById->getElementById(elementId.impl(), this);
 }
 
 void TreeScope::addElementById(const AtomicString& elementId, Element* element)
 {
-    m_elementsById.add(elementId.impl(), element);
+    if (!m_elementsById)
+        m_elementsById = adoptPtr(new DocumentOrderedMap);
+    m_elementsById->add(elementId.impl(), element);
     m_idTargetObserverRegistry->notifyObservers(elementId);
 }
 
 void TreeScope::removeElementById(const AtomicString& elementId, Element* element)
 {
-    m_elementsById.remove(elementId.impl(), element);
+    if (!m_elementsById)
+        return;
+    m_elementsById->remove(elementId.impl(), element);
     m_idTargetObserverRegistry->notifyObservers(elementId);
 }
 
@@ -125,42 +131,54 @@
     AtomicStringImpl* name = imageMap->getName().impl();
     if (!name)
         return;
-    m_imageMapsByName.add(name, imageMap);
+    if (!m_imageMapsByName)
+        m_imageMapsByName = adoptPtr(new DocumentOrderedMap);
+    m_imageMapsByName->add(name, imageMap);
 }
 
 void TreeScope::removeImageMap(HTMLMapElement* imageMap)
 {
+    if (!m_imageMapsByName)
+        return;
     AtomicStringImpl* name = imageMap->getName().impl();
     if (!name)
         return;
-    m_imageMapsByName.remove(name, imageMap);
+    m_imageMapsByName->remove(name, imageMap);
 }
 
 HTMLMapElement* TreeScope::getImageMap(const String& url) const
 {
     if (url.isNull())
         return 0;
+    if (!m_imageMapsByName)
+        return 0;
     size_t hashPos = url.find('#');
     String name = (hashPos == notFound ? url : url.substring(hashPos + 1)).impl();
     if (rootNode()->document()->isHTMLDocument())
-        return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
-    return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByMapName(AtomicString(name).impl(), this));
+        return static_cast<HTMLMapElement*>(m_imageMapsByName->getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
+    return static_cast<HTMLMapElement*>(m_imageMapsByName->getElementByMapName(AtomicString(name).impl(), this));
 }
 
 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
 {
-    m_labelsByForAttribute.add(forAttributeValue.impl(), element);
+    ASSERT(m_labelsByForAttribute);
+    m_labelsByForAttribute->add(forAttributeValue.impl(), element);
 }
 
 void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
 {
-    m_labelsByForAttribute.remove(forAttributeValue.impl(), element);
+    ASSERT(m_labelsByForAttribute);
+    m_labelsByForAttribute->remove(forAttributeValue.impl(), element);
 }
 
 HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeValue)
 {
-    if (!m_shouldCacheLabelsByForAttribute) {
-        m_shouldCacheLabelsByForAttribute = true;
+    if (forAttributeValue.isEmpty())
+        return 0;
+
+    if (!m_labelsByForAttribute) {
+        // Populate the map on first access.
+        m_labelsByForAttribute = adoptPtr(new DocumentOrderedMap);
         for (Node* node = rootNode(); node; node = node->traverseNextNode()) {
             if (node->hasTagName(labelTag)) {
                 HTMLLabelElement* label = static_cast<HTMLLabelElement*>(node);
@@ -171,10 +189,7 @@
         }
     }
 
-    if (forAttributeValue.isEmpty())
-        return 0;
-
-    return static_cast<HTMLLabelElement*>(m_labelsByForAttribute.getElementByLabelForAttribute(forAttributeValue.impl(), this));
+    return static_cast<HTMLLabelElement*>(m_labelsByForAttribute->getElementByLabelForAttribute(forAttributeValue.impl(), this));
 }
 
 DOMSelection* TreeScope::getSelection() const

Modified: trunk/Source/WebCore/dom/TreeScope.h (135938 => 135939)


--- trunk/Source/WebCore/dom/TreeScope.h	2012-11-28 00:24:25 UTC (rev 135938)
+++ trunk/Source/WebCore/dom/TreeScope.h	2012-11-28 00:34:19 UTC (rev 135939)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All Rights Reserved.
+ * Copyright (C) 2012 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -64,7 +65,7 @@
     HTMLMapElement* getImageMap(const String& url) const;
 
     // For accessibility.
-    bool shouldCacheLabelsByForAttribute() const { return m_shouldCacheLabelsByForAttribute; }
+    bool shouldCacheLabelsByForAttribute() const { return m_labelsByForAttribute; }
     void addLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
     void removeLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
     HTMLLabelElement* labelElementForId(const AtomicString& forAttributeValue);
@@ -100,12 +101,10 @@
     ContainerNode* m_rootNode;
     TreeScope* m_parentTreeScope;
 
-    DocumentOrderedMap m_elementsById;
-    DocumentOrderedMap m_imageMapsByName;
+    OwnPtr<DocumentOrderedMap> m_elementsById;
+    OwnPtr<DocumentOrderedMap> m_imageMapsByName;
+    OwnPtr<DocumentOrderedMap> m_labelsByForAttribute;
 
-    DocumentOrderedMap m_labelsByForAttribute;
-    bool m_shouldCacheLabelsByForAttribute;
-
     OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry;
 
     mutable RefPtr<DOMSelection> m_selection;
@@ -114,12 +113,12 @@
 inline bool TreeScope::hasElementWithId(AtomicStringImpl* id) const
 {
     ASSERT(id);
-    return m_elementsById.contains(id);
+    return m_elementsById && m_elementsById->contains(id);
 }
 
 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) const
 {
-    return m_elementsById.containsMultiple(id.impl());
+    return m_elementsById && m_elementsById->containsMultiple(id.impl());
 }
 
 TreeScope* commonTreeScope(Node*, Node*);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to