Shrink-to-fit Display::LineBox/Display::Run vectors.
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Feb 2020 15:21:29 +0000 (15:21 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Feb 2020 15:21:29 +0000 (15:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208343

Reviewed by Antti Koivisto.

From the collected data in PLT5, 95% of Runs / LineBoxes are <= 4, while we are having 10 and 5 inlineCapacity.
We adjust this inlineCapacity to 4 based on this number. It also covers almost all of Speedometer2.0 content (in it, 99.9% is 1).
We also call `shrinkToFit` to make it the exact size after baking Display::InlineContent. It should be no-op in 95% cases.

* layout/displaytree/DisplayInlineContent.h:
* layout/inlineformatting/InlineFormattingState.h:
(WebCore::Layout::InlineFormattingState::shrinkDisplayInlineContent):
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::layout):

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

Source/WebCore/ChangeLog
Source/WebCore/layout/displaytree/DisplayInlineContent.h
Source/WebCore/layout/inlineformatting/InlineFormattingState.h
Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp

index b5a1a14..1ba89ac 100644 (file)
@@ -1,3 +1,20 @@
+2020-02-28  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        Shrink-to-fit Display::LineBox/Display::Run vectors.
+        https://bugs.webkit.org/show_bug.cgi?id=208343
+
+        Reviewed by Antti Koivisto.
+
+        From the collected data in PLT5, 95% of Runs / LineBoxes are <= 4, while we are having 10 and 5 inlineCapacity.
+        We adjust this inlineCapacity to 4 based on this number. It also covers almost all of Speedometer2.0 content (in it, 99.9% is 1).
+        We also call `shrinkToFit` to make it the exact size after baking Display::InlineContent. It should be no-op in 95% cases.
+
+        * layout/displaytree/DisplayInlineContent.h:
+        * layout/inlineformatting/InlineFormattingState.h:
+        (WebCore::Layout::InlineFormattingState::shrinkDisplayInlineContent):
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::layout):
+
 2020-02-28  Alberto Garcia  <berto@igalia.com>
 
         [GStreamer] Unreviewed. Fix build warning.
index d7dddb3..7034438 100644 (file)
@@ -38,8 +38,8 @@ namespace Display {
 struct InlineContent : public RefCounted<InlineContent> {
     ~InlineContent();
 
-    using Runs = Vector<Run, 10>;
-    using LineBoxes = Vector<LineBox, 5>;
+    using Runs = Vector<Run, 4>;
+    using LineBoxes = Vector<LineBox, 4>;
 
     Runs runs;
     LineBoxes lineBoxes;
index f7bdb3b..6879d41 100644 (file)
@@ -50,7 +50,9 @@ public:
 
     const Display::InlineContent* displayInlineContent() const { return m_displayInlineContent.get(); }
     Display::InlineContent& ensureDisplayInlineContent();
+
     void clearDisplayInlineContent() { m_displayInlineContent = nullptr; }
+    void shrinkDisplayInlineContent();
 
 private:
     // Cacheable input to line layout.
@@ -66,6 +68,14 @@ inline Display::InlineContent& InlineFormattingState::ensureDisplayInlineContent
     return *m_displayInlineContent;
 }
 
+inline void InlineFormattingState::shrinkDisplayInlineContent()
+{
+    if (!m_displayInlineContent)
+        return;
+    m_displayInlineContent->runs.shrinkToFit();
+    m_displayInlineContent->lineBoxes.shrinkToFit();
+}
+
 }
 }
 
index e4be04a..e8db378 100644 (file)
@@ -111,6 +111,7 @@ void LineLayout::layout()
     auto verticalConstraints = Layout::VerticalConstraints { m_flow.borderAndPaddingBefore(), { } };
 
     inlineFormattingContext.layoutInFlowContent(invalidationState, horizontalConstraints, verticalConstraints);
+    m_inlineFormattingState.shrinkDisplayInlineContent();
 }
 
 void LineLayout::prepareLayoutState()