Bug 1390760 - Measure ServoComputedData::visited_style. r=bholley.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 21 Aug 2017 16:07:16 +1000
changeset 650247 50fd4bb9897fb179ceeca364b04469c19900cc60
parent 650231 6aa04814065027c6bc342ab5f03afdeb8a205390
child 650248 9bf9368c50e1460309429e7615519b9a5af2a118
child 650249 9a9ec2b5498fc4d6c16ec47f442daa6f21015302
child 650251 ede6c6cfcbb1fe89683f4a00c03ff6ded493e86f
child 650278 fe7d953913e0b272eb9b1193c2095f0e4574519e
child 650298 4757dbd31cb65b36833dd9f0d77b6b8dbeb11ff0
child 650299 defb1602cc9713b2855f04ae391dc05b7ac4a4b3
push id75304
push userttung@mozilla.com
push dateTue, 22 Aug 2017 02:40:58 +0000
reviewersbholley
bugs1390760
milestone57.0a1
Bug 1390760 - Measure ServoComputedData::visited_style. r=bholley. For the Obama wikipedia page, this covers about 85% of the unmeasured ComputedValues structs. The about:memory output looks like this: > +---2,443,648 B (02.41%) -- computed-values > | +--1,088,272 B (01.07%) -- dom > | +----945,744 B (00.93%) -- non-dom > | +----409,632 B (00.40%) -- visited I'm not sure why some CVs are still being missed. MozReview-Commit-ID: 1bYWwSi4ihn
dom/base/Element.cpp
dom/base/nsWindowMemoryReporter.cpp
dom/base/nsWindowSizes.h
layout/generic/nsFrame.cpp
layout/style/ServoBindings.cpp
layout/style/ServoStyleContext.h
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -4196,24 +4196,25 @@ Element::AddSizeOfExcludingThis(SizeOfSt
                                               &aState.mSeenPtrs, this);
 
     // Now measure just the ComputedValues (and style structs) under
     // mServoData. This counts towards the relevant fields in |aSizes|.
     RefPtr<ServoStyleContext> sc;
     if (Servo_Element_HasPrimaryComputedValues(this)) {
       sc = Servo_Element_GetPrimaryComputedValues(this).Consume();
       if (!aState.HaveSeenPtr(sc.get())) {
-        sc->AddSizeOfIncludingThis(aState, aSizes, /* isDOM = */ true);
+        sc->AddSizeOfIncludingThis(aState, aSizes, &aSizes.mComputedValuesDom);
       }
 
       for (size_t i = 0; i < nsCSSPseudoElements::kEagerPseudoCount; i++) {
         if (Servo_Element_HasPseudoComputedValues(this, i)) {
           sc = Servo_Element_GetPseudoComputedValues(this, i).Consume();
           if (!aState.HaveSeenPtr(sc.get())) {
-            sc->AddSizeOfIncludingThis(aState, aSizes, /* isDOM = */ true);
+            sc->AddSizeOfIncludingThis(aState, aSizes,
+                                       &aSizes.mComputedValuesDom);
           }
         }
       }
     }
   }
 }
 
 struct DirtyDescendantsBit {
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -491,16 +491,22 @@ CollectWindowReports(nsGlobalWindow *aWi
 
   REPORT_SIZE("/layout/computed-values/non-dom",
               windowSizes.mStyleSizes.mComputedValuesNonDom,
               "Memory used by ComputedValues objects not accessible from DOM "
               "elements.");
   aWindowTotalSizes->mStyleSizes.mComputedValuesNonDom +=
     windowSizes.mStyleSizes.mComputedValuesNonDom;
 
+  REPORT_SIZE("/layout/computed-values/visited",
+              windowSizes.mStyleSizes.mComputedValuesVisited,
+              "Memory used by ComputedValues objects used for visited styles.");
+  aWindowTotalSizes->mStyleSizes.mComputedValuesVisited +=
+    windowSizes.mStyleSizes.mComputedValuesVisited;
+
 #undef REPORT_SIZE
 #undef REPORT_COUNT
 }
 
 typedef nsTArray< RefPtr<nsGlobalWindow> > WindowArray;
 
 NS_IMETHODIMP
 nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
@@ -654,17 +660,18 @@ nsWindowMemoryReporter::CollectReports(n
 #undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
 
   REPORT("window-objects/layout/servo-style-structs", styleTotal,
          "Memory used for style structs within windows. This is the sum of "
          "all windows' 'layout/servo-style-structs/' numbers.");
 
   REPORT("window-objects/layout/computed-values",
          windowTotalSizes.mStyleSizes.mComputedValuesDom +
-         windowTotalSizes.mStyleSizes.mComputedValuesNonDom,
+         windowTotalSizes.mStyleSizes.mComputedValuesNonDom +
+         windowTotalSizes.mStyleSizes.mComputedValuesVisited,
          "This is the sum of all windows' 'layout/computed-values/' "
          "numbers.");
 
 #undef REPORT
 
   return NS_OK;
 }
 
--- a/dom/base/nsWindowSizes.h
+++ b/dom/base/nsWindowSizes.h
@@ -108,17 +108,18 @@ struct nsArenaSizes {
 };
 
 #define NS_STYLE_SIZES_FIELD(name_) mStyle##name_
 
 struct nsStyleSizes
 {
 #define FOR_EACH_SIZE(macro) \
   macro(Style, mComputedValuesDom) \
-  macro(Style, mComputedValuesNonDom)
+  macro(Style, mComputedValuesNonDom) \
+  macro(Style, mComputedValuesVisited)
 
   nsStyleSizes()
     :
       FOR_EACH_SIZE(ZERO_SIZE)
 
       #define STYLE_STRUCT(name_, cb_) \
         NS_STYLE_SIZES_FIELD(name_)(0),
       #define STYLE_STRUCT_LIST_IGNORE_VARIABLES
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -10717,17 +10717,17 @@ nsIFrame::AddSizeOfExcludingThisForTree(
     mProperties.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
 
   // We don't do this for Gecko because this stuff is stored in the nsPresArena
   // and so measured elsewhere.
   if (mStyleContext->IsServo()) {
     ServoStyleContext* sc = mStyleContext->AsServo();
     if (!aSizes.mState.HaveSeenPtr(sc)) {
       sc->AddSizeOfIncludingThis(aSizes.mState, aSizes.mStyleSizes,
-                                 /* isDOM = */ false);
+                                 &aSizes.mStyleSizes.mComputedValuesNonDom);
     }
   }
 
   FrameChildListIterator iter(this);
   while (!iter.IsDone()) {
     for (const nsIFrame* f : iter.CurrentList()) {
       f->AddSizeOfExcludingThisForTree(aSizes);
     }
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -258,16 +258,28 @@ ServoComputedData::AddSizeOfExcludingThi
   if (!aState.HaveSeenPtr(p##name_)) { \
     aSizes.NS_STYLE_SIZES_FIELD(name_) += \
       ServoStyleStructsMallocSizeOf(p##name_); \
   }
   #define STYLE_STRUCT_LIST_IGNORE_VARIABLES
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
 #undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
+
+  if (visited_style.mPtr && !aState.HaveSeenPtr(visited_style.mPtr)) {
+    visited_style.mPtr->AddSizeOfIncludingThis(
+      aState, aSizes, &aSizes.mComputedValuesVisited);
+  }
+
+  // Measurement of the following members may be added later if DMD finds it is
+  // worthwhile:
+  // - custom_properties
+  // - writing_mode
+  // - rules
+  // - font_computation_data
 }
 
 void
 Gecko_ServoStyleContext_Destroy(ServoStyleContext* aContext)
 {
   aContext->~ServoStyleContext();
 }
 
--- a/layout/style/ServoStyleContext.h
+++ b/layout/style/ServoStyleContext.h
@@ -95,36 +95,35 @@ public:
   }
 
   /**
    * Makes this context match |aOther| in terms of which style structs have
    * been resolved.
    */
   inline void ResolveSameStructsAs(const ServoStyleContext* aOther);
 
+  // The |aCVsSize| outparam on this function is where the actual CVs size
+  // value is added. It's done that way because the callers know which value
+  // the size should be added to.
   void AddSizeOfIncludingThis(SizeOfState& aState, nsStyleSizes& aSizes,
-                              bool aIsDOM) const
+                              size_t* aCVsSize) const
   {
     // XXX WARNING: similar to ServoComputedData::AddSizeOfExcludingThis(),
     // but here we need to step back 4 or 8 bytes to get past the servo_arc::Arc
     // refcount to the base pointer.
     static_assert(alignof(ServoStyleContext) == 4 ||
                   alignof(ServoStyleContext) == 8,
                   "alignment will break AddSizeOfExcludingThis()");
     const char* p = reinterpret_cast<const char*>(this);
     p -= std::max(sizeof(size_t), alignof(ServoStyleContext));
 
     // We use ServoComputedValuesMallocSizeOf rather than
     // |aState.mMallocSizeOf| to better distinguish in DMD's output the memory
     // measured here.
-    if (aIsDOM) {
-      aSizes.mComputedValuesDom += ServoComputedValuesMallocSizeOf(p);
-    } else {
-      aSizes.mComputedValuesNonDom += ServoComputedValuesMallocSizeOf(p);
-    }
+    *aCVsSize += ServoComputedValuesMallocSizeOf(p);
     mSource.AddSizeOfExcludingThis(aState, aSizes);
   }
 
 private:
   nsPresContext* mPresContext;
   ServoComputedData mSource;
 
   // A linked-list cache of inheriting anon boxes inheriting from this style _if