Bug 1399758 - Measure ImageValue objects. r=heycam.
☠☠ backed out by a7f12e31f7e0 ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 14 Sep 2017 18:48:19 +1000
changeset 430576 1536fa69bad4d6ee7f1f4c265fab57504f6263d9
parent 430575 e2f8c9f76b711c89b04ca0e2f2ac324e638ac704
child 430577 c60b5da550ea3b664a9a81fb5dd9708bf7491657
push id7768
push userryanvm@gmail.com
push dateSat, 16 Sep 2017 16:13:49 +0000
treeherdermozilla-beta@3b375d85383a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1399758
milestone57.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 1399758 - Measure ImageValue objects. r=heycam. We have about 11,500 of these when loading gmail in a Stylo-enabled build, from SpecifiedUrls; the objects themselves account for about 1.3 MiB of memory, and the strings within them about 2.9 MiB. We also have a very small number of them on the Gecko side. MozReview-Commit-ID: AduCIaDIzGG
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1522,16 +1522,24 @@ Gecko_ImageValue_Create(ServoBundledURI 
   NS_ConvertUTF8toUTF16 url(reinterpret_cast<const char*>(aURI.mURLString),
                             aURI.mURLStringLength);
 
   RefPtr<css::ImageValue> value(
     new css::ImageValue(url, do_AddRef(aURI.mExtraData)));
   return value.forget().take();
 }
 
+MOZ_DEFINE_MALLOC_SIZE_OF(GeckoImageValueMallocSizeOf)
+
+size_t
+Gecko_ImageValue_SizeOfIncludingThis(mozilla::css::ImageValue* aImageValue)
+{
+  return aImageValue->SizeOfIncludingThis(GeckoImageValueMallocSizeOf);
+}
+
 void
 Gecko_SetLayerImageImageValue(nsStyleImage* aImage,
                               mozilla::css::ImageValue* aImageValue)
 {
   MOZ_ASSERT(aImage && aImageValue);
 
   RefPtr<nsStyleImageRequest> req =
     CreateStyleImageRequest(nsStyleImageRequest::Mode::Track, aImageValue);
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -338,16 +338,17 @@ nsIAtom* Gecko_CounterStyle_GetName(cons
 const mozilla::AnonymousCounterStyle*
 Gecko_CounterStyle_GetAnonymous(const mozilla::CounterStylePtr* ptr);
 
 // background-image style.
 void Gecko_SetNullImageValue(nsStyleImage* image);
 void Gecko_SetGradientImageValue(nsStyleImage* image, nsStyleGradient* gradient);
 NS_DECL_THREADSAFE_FFI_REFCOUNTING(mozilla::css::ImageValue, ImageValue);
 mozilla::css::ImageValue* Gecko_ImageValue_Create(ServoBundledURI aURI);
+size_t Gecko_ImageValue_SizeOfIncludingThis(mozilla::css::ImageValue* aImageValue);
 void Gecko_SetLayerImageImageValue(nsStyleImage* image,
                                    mozilla::css::ImageValue* aImageValue);
 
 void Gecko_SetImageElement(nsStyleImage* image, nsIAtom* atom);
 void Gecko_CopyImageValueFrom(nsStyleImage* image, const nsStyleImage* other);
 void Gecko_InitializeImageCropRect(nsStyleImage* image);
 
 nsStyleGradient* Gecko_CreateGradient(uint8_t shape,
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2145,18 +2145,17 @@ nsCSSValue::SizeOfExcludingThis(mozilla:
 
     // URL
     case eCSSUnit_URL:
       n += mValue.mURL->SizeOfIncludingThis(aMallocSizeOf);
       break;
 
     // Image
     case eCSSUnit_Image:
-      // Not yet measured.  Measurement may be added later if DMD finds it
-      // worthwhile.
+      n += mValue.mImage->SizeOfIncludingThis(aMallocSizeOf);
       break;
 
     // Gradient
     case eCSSUnit_Gradient:
       n += mValue.mGradient->SizeOfIncludingThis(aMallocSizeOf);
       break;
 
     // TokenStream
@@ -3072,16 +3071,25 @@ css::ImageValue::~ImageValue()
       proxy->CancelAndForgetObserver(NS_BINDING_ABORTED);
     }
 
     iter.Remove();
   }
 }
 
 size_t
+css::ImageValue::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  size_t n = aMallocSizeOf(this);
+  n += css::URLValueData::SizeOfExcludingThis(aMallocSizeOf);
+  n += mRequests.ShallowSizeOfExcludingThis(aMallocSizeOf);
+  return n;
+}
+
+size_t
 css::ComplexColorValue::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   // Only measure it if it's unshared, to avoid double-counting.
   size_t n = 0;
   if (mRefCnt <= 1) {
     n += aMallocSizeOf(this);
   }
   return n;
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -214,17 +214,17 @@ struct ImageValue final : public URLValu
   ImageValue(const nsAString& aString,
              already_AddRefed<URLExtraData> aExtraData);
 
   ImageValue(const ImageValue&) = delete;
   ImageValue& operator=(const ImageValue&) = delete;
 
   void Initialize(nsIDocument* aDocument);
 
-  // XXXheycam We should have our own SizeOfIncludingThis method.
+  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 protected:
   ~ImageValue();
 
 public:
   // Inherit Equals from URLValueData
 
   nsRefPtrHashtable<nsPtrHashKey<nsIDocument>, imgRequestProxy> mRequests;