Title: [233173] trunk/Source/WebCore
Revision
233173
Author
simon.fra...@apple.com
Date
2018-06-25 14:15:21 -0700 (Mon, 25 Jun 2018)

Log Message

MatchedPropertiesCacheItem wastes 388KB of vector capacity on nytimes.com
https://bugs.webkit.org/show_bug.cgi?id=186990

Reviewed by Antti Koivisto.

MatchedPropertiesCacheItem.matchedProperties was appended to, so it allocated capacity
in 16-size chunks. Instead, assign to it so it only allocates as much capacity as is needed.
Copy-constructing is more wasteful, since it copies the 64-chunk size from the right-hand side.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::addToMatchedPropertiesCache):
* css/StyleResolver.h:
(WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (233172 => 233173)


--- trunk/Source/WebCore/ChangeLog	2018-06-25 21:14:07 UTC (rev 233172)
+++ trunk/Source/WebCore/ChangeLog	2018-06-25 21:15:21 UTC (rev 233173)
@@ -1,3 +1,19 @@
+2018-06-25  Simon Fraser  <simon.fra...@apple.com>
+
+        MatchedPropertiesCacheItem wastes 388KB of vector capacity on nytimes.com
+        https://bugs.webkit.org/show_bug.cgi?id=186990
+
+        Reviewed by Antti Koivisto.
+
+        MatchedPropertiesCacheItem.matchedProperties was appended to, so it allocated capacity
+        in 16-size chunks. Instead, assign to it so it only allocates as much capacity as is needed.
+        Copy-constructing is more wasteful, since it copies the 64-chunk size from the right-hand side.
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::addToMatchedPropertiesCache):
+        * css/StyleResolver.h:
+        (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem):
+
 2018-06-25  Chris Dumez  <cdu...@apple.com>
 
         Null dereference crash un ApplicationCacheGroup::startLoadingEntry()

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (233172 => 233173)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2018-06-25 21:14:07 UTC (rev 233172)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2018-06-25 21:15:21 UTC (rev 233173)
@@ -1251,13 +1251,9 @@
     }
 
     ASSERT(hash);
-    MatchedPropertiesCacheItem cacheItem;
-    cacheItem.matchedProperties.appendVector(matchResult.matchedProperties());
-    cacheItem.ranges = matchResult.ranges;
     // Note that we don't cache the original RenderStyle instance. It may be further modified.
     // The RenderStyle in the cache is really just a holder for the substructures and never used as-is.
-    cacheItem.renderStyle = RenderStyle::clonePtr(*style);
-    cacheItem.parentRenderStyle = RenderStyle::clonePtr(*parentStyle);
+    MatchedPropertiesCacheItem cacheItem(matchResult, style, parentStyle);
     m_matchedPropertiesCache.add(hash, WTFMove(cacheItem));
 }
 

Modified: trunk/Source/WebCore/css/StyleResolver.h (233172 => 233173)


--- trunk/Source/WebCore/css/StyleResolver.h	2018-06-25 21:14:07 UTC (rev 233172)
+++ trunk/Source/WebCore/css/StyleResolver.h	2018-06-25 21:15:21 UTC (rev 233173)
@@ -468,6 +468,16 @@
         MatchRanges ranges;
         std::unique_ptr<RenderStyle> renderStyle;
         std::unique_ptr<RenderStyle> parentRenderStyle;
+        
+        MatchedPropertiesCacheItem(const MatchResult& matchResult, const RenderStyle* style, const RenderStyle* parentStyle)
+            : ranges(matchResult.ranges)
+            , renderStyle(RenderStyle::clonePtr(*style))
+            , parentRenderStyle(RenderStyle::clonePtr(*parentStyle))
+        {
+            // Assign rather than copy-construct so we only allocate as much vector capacity as needed.
+            matchedProperties = matchResult.matchedProperties();
+        }
+        MatchedPropertiesCacheItem() = default;
     };
     const MatchedPropertiesCacheItem* findFromMatchedPropertiesCache(unsigned hash, const MatchResult&);
     void addToMatchedPropertiesCache(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to