Use inline capacity for StylePropertyShorthand Vectors.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Jun 2016 18:14:25 +0000 (18:14 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Jun 2016 18:14:25 +0000 (18:14 +0000)
<https://webkit.org/b/158260>

Reviewed by Antti Koivisto.

Vector<StylePropertyShorthand> was a huge source of heap allocations,
just over 0.5% of all fastMalloc() bytes on PLUM. Giving it an inline capacity
of 4 turns all of it into stack allocations.

* css/CSSParser.cpp:
(WebCore::CSSParser::addProperty):
* css/CSSProperty.cpp:
(WebCore::StylePropertyMetadata::shorthandID):
* css/StylePropertyShorthand.cpp:
(WebCore::indexOfShorthandForLonghand):
* css/StylePropertyShorthand.h:
* css/makeprop.pl:
(constructShorthandsVector):

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSProperty.cpp
Source/WebCore/css/StylePropertyShorthand.cpp
Source/WebCore/css/StylePropertyShorthand.h
Source/WebCore/css/makeprop.pl

index 22e4f7e..ccf29cf 100644 (file)
@@ -1,3 +1,24 @@
+2016-06-01  Andreas Kling  <akling@apple.com>
+
+        Use inline capacity for StylePropertyShorthand Vectors.
+        <https://webkit.org/b/158260>
+
+        Reviewed by Antti Koivisto.
+
+        Vector<StylePropertyShorthand> was a huge source of heap allocations,
+        just over 0.5% of all fastMalloc() bytes on PLUM. Giving it an inline capacity
+        of 4 turns all of it into stack allocations.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::addProperty):
+        * css/CSSProperty.cpp:
+        (WebCore::StylePropertyMetadata::shorthandID):
+        * css/StylePropertyShorthand.cpp:
+        (WebCore::indexOfShorthandForLonghand):
+        * css/StylePropertyShorthand.h:
+        * css/makeprop.pl:
+        (constructShorthandsVector):
+
 2016-06-01  Nael Ouedraogo  <nael.ouedraogo@crf.canon.fr>
 
         POST request on a blob resource should return a "network error" instead of HTTP 500 response
index a4994f6..90fffbf 100644 (file)
@@ -1609,7 +1609,7 @@ void CSSParser::addProperty(CSSPropertyID propId, RefPtr<CSSValue>&& value, bool
         return;
     }
 
-    Vector<StylePropertyShorthand> shorthands = matchingShorthandsForLonghand(propId);
+    auto shorthands = matchingShorthandsForLonghand(propId);
     if (shorthands.size() == 1)
         m_parsedProperties.append(CSSProperty(propId, WTFMove(value), important, true, CSSPropertyInvalid, m_implicitShorthand || implicit));
     else
index e0857f5..d61116b 100644 (file)
@@ -43,7 +43,7 @@ CSSPropertyID StylePropertyMetadata::shorthandID() const
     if (!m_isSetFromShorthand)
         return CSSPropertyInvalid;
 
-    Vector<StylePropertyShorthand> shorthands = matchingShorthandsForLonghand(static_cast<CSSPropertyID>(m_propertyID));
+    auto shorthands = matchingShorthandsForLonghand(static_cast<CSSPropertyID>(m_propertyID));
     ASSERT(shorthands.size() && m_indexInShorthandsVector >= 0 && m_indexInShorthandsVector < shorthands.size());
     return shorthands[m_indexInShorthandsVector].id();
 }
index ac3a909..2e5999c 100644 (file)
@@ -68,7 +68,7 @@ bool isShorthandCSSProperty(CSSPropertyID id)
     return shorthandForProperty(id).length();
 }
 
-unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const Vector<StylePropertyShorthand>& shorthands)
+unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const StylePropertyShorthandVector& shorthands)
 {
     for (unsigned i = 0, size = shorthands.size(); i < size; ++i) {
         if (shorthands[i].id() == shorthandID)
index 715f3b7..a8757c1 100644 (file)
@@ -61,9 +61,10 @@ StylePropertyShorthand shorthandForProperty(CSSPropertyID);
 
 // Return the list of shorthands for a given longhand.
 // The implementation is generated in StylePropertyShorthandFunctions.cpp.
-Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID);
+using StylePropertyShorthandVector = Vector<StylePropertyShorthand, 4>;
+StylePropertyShorthandVector matchingShorthandsForLonghand(CSSPropertyID);
 
-unsigned indexOfShorthandForLonghand(CSSPropertyID, const Vector<StylePropertyShorthand>&);
+unsigned indexOfShorthandForLonghand(CSSPropertyID, const StylePropertyShorthandVector&);
 
 bool isShorthandCSSProperty(CSSPropertyID);
 
index 5df3627..2631e32 100755 (executable)
@@ -1005,7 +1005,7 @@ print SHORTHANDS_CPP << "EOF";
 EOF
 
 print SHORTHANDS_CPP << "EOF";
-Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID propertyID)
+StylePropertyShorthandVector matchingShorthandsForLonghand(CSSPropertyID propertyID)
 {
     switch (propertyID) {
 EOF
@@ -1013,7 +1013,7 @@ EOF
 sub constructShorthandsVector {
   my $shorthands = shift;
 
-  my $vector = "Vector<StylePropertyShorthand>{";
+  my $vector = "StylePropertyShorthandVector{";
   foreach my $i (0 .. $#$shorthands) {
     $vector .= ", " unless $i == 0;
     $vector .= lcfirst($nameToId{$shorthands->[$i]}) . "Shorthand()";