Bug 1480146 - Add memory reporting for the inline style cache. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 16 Aug 2019 10:56:25 +0000
changeset 488492 ff3ba7a16c214c01e270483ba42dc37e5bcd22f6
parent 488491 f47314ec33ff5b6f1eaf95ca1a721bcf34ce5554
child 488493 f24a38d1b40a971a2de2ec06e144c1d7b4220c78
push id36444
push userccoroiu@mozilla.com
push dateFri, 16 Aug 2019 16:24:18 +0000
treeherdermozilla-central@8a9e9189cd98 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1480146
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1480146 - Add memory reporting for the inline style cache. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D41731
layout/style/Loader.cpp
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -464,16 +464,18 @@ struct Loader::Sheets {
   nsRefPtrHashtable<nsStringHashKey, StyleSheet> mInlineSheets;
 
 
   RefPtr<StyleSheet> LookupInline(const nsAString&);
 
   // A cache hit or miss. It is a miss if the `StyleSheet` is null.
   using CacheResult = Tuple<RefPtr<StyleSheet>, SheetState>;
   CacheResult Lookup(SheetLoadDataHashKey&, bool aSyncLoad);
+
+  size_t SizeOfIncludingThis(MallocSizeOf) const;
 };
 
 RefPtr<StyleSheet> Loader::Sheets::LookupInline(const nsAString& aBuffer) {
   auto result = mInlineSheets.Lookup(aBuffer);
   if (!result) {
     return nullptr;
   }
   if (result.Data()->HasForcedUniqueInner()) {
@@ -573,16 +575,49 @@ auto Loader::Sheets::Lookup(SheetLoadDat
     LOG(("  From pending: %p", data->mSheet.get()));
     AssertIncompleteSheetMatches(*data, aKey);
     return MakeTuple(CloneSheet(*data->mSheet), SheetState::Pending);
   }
 
   return {};
 }
 
+size_t Loader::Sheets::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
+  size_t n = aMallocSizeOf(this);
+
+  n += mCompleteSheets.ShallowSizeOfExcludingThis(aMallocSizeOf);
+  for (auto iter = mCompleteSheets.ConstIter(); !iter.Done(); iter.Next()) {
+    // If the sheet has a parent, then its parent will report it so we don't
+    // have to worry about it here. Likewise, if aSheet has an owning node, then
+    // the document that node is in will report it.
+    const StyleSheet* sheet = iter.UserData();
+    if (!sheet->GetOwnerNode() && !sheet->GetParentSheet()) {
+      n += sheet->SizeOfIncludingThis(aMallocSizeOf);
+    }
+  }
+
+  n += mInlineSheets.ShallowSizeOfExcludingThis(aMallocSizeOf);
+  for (auto iter = mInlineSheets.ConstIter(); !iter.Done(); iter.Next()) {
+    n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+    // If the sheet has a parent, then its parent will report it so we don't
+    // have to worry about it here.
+    const StyleSheet* sheet = iter.UserData();
+    MOZ_ASSERT(!sheet->GetParentSheet(), "How did an @import rule end up here?");
+    if (!sheet->GetOwnerNode()) {
+      n += sheet->SizeOfIncludingThis(aMallocSizeOf);
+    }
+  }
+
+  // Measurement of the following members may be added later if DMD finds it is
+  // worthwhile:
+  // - mLoadingDatas: transient, and should be small
+  // - mPendingDatas: transient, and should be small
+  return n;
+}
+
 /*************************
  * Loader Implementation *
  *************************/
 
 Loader::Loader()
     : mDocument(nullptr),
       mDatasToNotifyOn(0),
       mCompatMode(eCompatibility_FullStandards),
@@ -2435,38 +2470,26 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Lo
     tmp->mSheets->mCompleteSheets.Clear();
   }
   tmp->mObservers.Clear();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Loader, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Loader, Release)
 
-size_t Loader::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
+size_t Loader::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
   size_t n = aMallocSizeOf(this);
 
   if (mSheets) {
-    n += mSheets->mCompleteSheets.ShallowSizeOfExcludingThis(aMallocSizeOf);
-    for (auto iter = mSheets->mCompleteSheets.ConstIter(); !iter.Done();
-         iter.Next()) {
-      // If aSheet has a parent, then its parent will report it so we don't
-      // have to worry about it here. Likewise, if aSheet has an owning node,
-      // then the document that node is in will report it.
-      const StyleSheet* sheet = iter.UserData();
-      n += (sheet->GetOwnerNode() || sheet->GetParentSheet())
-               ? 0
-               : sheet->SizeOfIncludingThis(aMallocSizeOf);
-    }
+    n += mSheets->SizeOfIncludingThis(aMallocSizeOf);
   }
   n += mObservers.ShallowSizeOfExcludingThis(aMallocSizeOf);
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
-  // - mLoadingDatas: transient, and should be small
-  // - mPendingDatas: transient, and should be small
   // - mPostedEvents: transient, and should be small
   //
   // The following members aren't measured:
   // - mDocument, because it's a weak backpointer
 
   return n;
 }