Bug 1387958 - Measure the stylist during memory reporting. r=heycam.
Example output from the Obama Wikipedia page:
> ├──2,315,600 B (01.16%) -- stylist
> │ ├──1,916,928 B (00.96%) ── invalidation-map
> │ ├────228,800 B (00.11%) ── rule-tree
> │ ├────142,336 B (00.07%) ── element-and-pseudos-maps
> │ ├─────14,336 B (00.01%) ── revalidation-selectors
> │ ├──────9,648 B (00.00%) ── other
> │ └──────3,552 B (00.00%) ── precomputed-pseudos
This change requires new code to measure HashMaps, which uses the new
'malloc_enclosing_size_of' functions that can measure a heap block from an
interior pointer.
The patch changes MallocSizeOfFn to a newtype, and introduces
MallocEnclosingSizeOfFn alongside.
It also adds new traits: MallocSizeOfBox, MallocSizeOfVec, MallocSizeOfHash.
These each contain a single method that does shallow measurement of the
relevant type, which is often useful. (This is a different style to the
existing MallocSizeOf trait, which does deep measurement, but I'm moving away
from the always-deep-measurement style because it's less flexible.)
MozReview-Commit-ID: FgJCCmdw0ZF
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -370,16 +370,51 @@ CollectWindowReports(nsGlobalWindow *aWi
REPORT_SIZE("/layout/servo-style-sets/stylist/rule-tree",
windowSizes.mLayoutServoStyleSetsStylistRuleTree,
"Memory used by rule trees within Servo style sets within a "
"window.");
aWindowTotalSizes->mLayoutServoStyleSetsStylistRuleTree +=
windowSizes.mLayoutServoStyleSetsStylistRuleTree;
+ REPORT_SIZE("/layout/servo-style-sets/stylist/precomputed-pseudos",
+ windowSizes.mLayoutServoStyleSetsStylistPrecomputedPseudos,
+ "Memory used by precomputed pseudo-element declarations within "
+ "Servo style sets within a window.");
+ aWindowTotalSizes->mLayoutServoStyleSetsStylistPrecomputedPseudos +=
+ windowSizes.mLayoutServoStyleSetsStylistPrecomputedPseudos;
+
+ REPORT_SIZE("/layout/servo-style-sets/stylist/element-and-pseudos-maps",
+ windowSizes.mLayoutServoStyleSetsStylistElementAndPseudosMaps,
+ "Memory used by element and pseudos maps within Servo style "
+ "sets within a window.");
+ aWindowTotalSizes->mLayoutServoStyleSetsStylistElementAndPseudosMaps +=
+ windowSizes.mLayoutServoStyleSetsStylistElementAndPseudosMaps;
+
+ REPORT_SIZE("/layout/servo-style-sets/stylist/invalidation-map",
+ windowSizes.mLayoutServoStyleSetsStylistInvalidationMap,
+ "Memory used by invalidation maps within Servo style sets "
+ "within a window.");
+ aWindowTotalSizes->mLayoutServoStyleSetsStylistInvalidationMap +=
+ windowSizes.mLayoutServoStyleSetsStylistInvalidationMap;
+
+ REPORT_SIZE("/layout/servo-style-sets/stylist/revalidation-selectors",
+ windowSizes.mLayoutServoStyleSetsStylistRevalidationSelectors,
+ "Memory used by selectors for cache revalidation within Servo "
+ "style sets within a window.");
+ aWindowTotalSizes->mLayoutServoStyleSetsStylistRevalidationSelectors +=
+ windowSizes.mLayoutServoStyleSetsStylistRevalidationSelectors;
+
+ REPORT_SIZE("/layout/servo-style-sets/stylist/other",
+ windowSizes.mLayoutServoStyleSetsStylistOther,
+ "Memory used by other Stylist data within Servo style sets "
+ "within a window.");
+ aWindowTotalSizes->mLayoutServoStyleSetsStylistOther +=
+ windowSizes.mLayoutServoStyleSetsStylistOther;
+
REPORT_SIZE("/layout/servo-style-sets/other",
windowSizes.mLayoutServoStyleSetsOther,
"Memory used by other parts of Servo style sets within a "
"window.");
aWindowTotalSizes->mLayoutServoStyleSetsOther +=
windowSizes.mLayoutServoStyleSetsOther;
REPORT_SIZE("/layout/text-runs", windowSizes.mLayoutTextRunsSize,
@@ -653,16 +688,21 @@ nsWindowMemoryReporter::CollectReports(n
"This is the sum of all windows' 'layout/arenas' numbers.");
REPORT("window-objects/layout/gecko-style-sets",
windowTotalSizes.mLayoutGeckoStyleSets,
"This is the sum of all windows' 'layout/gecko-style-sets' numbers.");
REPORT("window-objects/layout/servo-style-sets",
windowTotalSizes.mLayoutServoStyleSetsStylistRuleTree +
+ windowTotalSizes.mLayoutServoStyleSetsStylistPrecomputedPseudos +
+ windowTotalSizes.mLayoutServoStyleSetsStylistElementAndPseudosMaps +
+ windowTotalSizes.mLayoutServoStyleSetsStylistInvalidationMap +
+ windowTotalSizes.mLayoutServoStyleSetsStylistRevalidationSelectors +
+ windowTotalSizes.mLayoutServoStyleSetsStylistOther +
windowTotalSizes.mLayoutServoStyleSetsOther,
"This is the sum of all windows' 'layout/servo-style-sets/' numbers.");
REPORT("window-objects/layout/text-runs", windowTotalSizes.mLayoutTextRunsSize,
"This is the sum of all windows' 'layout/text-runs' numbers.");
REPORT("window-objects/layout/pres-contexts",
--- a/dom/base/nsWindowSizes.h
+++ b/dom/base/nsWindowSizes.h
@@ -172,16 +172,21 @@ class nsWindowSizes
macro(DOM, mDOMEventTargetsSize) \
macro(DOM, mDOMPerformanceUserEntries) \
macro(DOM, mDOMPerformanceResourceEntries) \
macro(DOM, mDOMOtherSize) \
macro(Style, mStyleSheetsSize) \
macro(Other, mLayoutPresShellSize) \
macro(Style, mLayoutGeckoStyleSets) \
macro(Style, mLayoutServoStyleSetsStylistRuleTree) \
+ macro(Style, mLayoutServoStyleSetsStylistPrecomputedPseudos) \
+ macro(Style, mLayoutServoStyleSetsStylistElementAndPseudosMaps) \
+ macro(Style, mLayoutServoStyleSetsStylistInvalidationMap) \
+ macro(Style, mLayoutServoStyleSetsStylistRevalidationSelectors) \
+ macro(Style, mLayoutServoStyleSetsStylistOther) \
macro(Style, mLayoutServoStyleSetsOther) \
macro(Other, mLayoutTextRunsSize) \
macro(Other, mLayoutPresContextSize) \
macro(Other, mLayoutFramePropertiesSize) \
macro(Style, mLayoutComputedValuesDom) \
macro(Style, mLayoutComputedValuesNonDom) \
macro(Style, mLayoutComputedValuesVisited) \
macro(Other, mPropertyTablesSize) \
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -111,16 +111,17 @@ SERVO_BINDING_FUNC(Servo_StyleSet_BuildF
gfxFontFeatureValueSet* list)
SERVO_BINDING_FUNC(Servo_StyleSet_ResolveForDeclarations,
ServoStyleContextStrong,
RawServoStyleSetBorrowed set,
ServoStyleContextBorrowedOrNull parent_style,
RawServoDeclarationBlockBorrowed declarations)
SERVO_BINDING_FUNC(Servo_StyleSet_AddSizeOfExcludingThis, void,
mozilla::MallocSizeOf malloc_size_of,
+ mozilla::MallocSizeOf malloc_enclosing_size_of,
mozilla::ServoStyleSetSizes* sizes,
RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_StyleContext_AddRef, void, ServoStyleContextBorrowed ctx);
SERVO_BINDING_FUNC(Servo_StyleContext_Release, void, ServoStyleContextBorrowed ctx);
SERVO_BINDING_FUNC(Servo_StyleSet_MightHaveAttributeDependency, bool,
RawServoStyleSetBorrowed set,
RawGeckoElementBorrowed element,
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -179,34 +179,48 @@ ServoStyleSet::MediumFeaturesChanged(boo
if (viewportUnitsUsed && aViewportChanged) {
return eRestyle_ForceDescendants;
}
return nsRestyleHint(0);
}
MOZ_DEFINE_MALLOC_SIZE_OF(ServoStyleSetMallocSizeOf)
+MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoStyleSetMallocEnclosingSizeOf)
void
ServoStyleSet::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const
{
MallocSizeOf mallocSizeOf = aSizes.mState.mMallocSizeOf;
aSizes.mLayoutServoStyleSetsOther += mallocSizeOf(this);
if (mRawSet) {
aSizes.mLayoutServoStyleSetsOther += mallocSizeOf(mRawSet.get());
ServoStyleSetSizes sizes;
// Measure mRawSet. We use ServoStyleSetMallocSizeOf rather than
// aMallocSizeOf to distinguish in DMD's output the memory measured within
// Servo code.
- Servo_StyleSet_AddSizeOfExcludingThis(ServoStyleSetMallocSizeOf, &sizes,
- mRawSet.get());
- aSizes.mLayoutServoStyleSetsStylistRuleTree += sizes.mStylistRuleTree;
- aSizes.mLayoutServoStyleSetsOther += sizes.mOther;
+ Servo_StyleSet_AddSizeOfExcludingThis(ServoStyleSetMallocSizeOf,
+ ServoStyleSetMallocEnclosingSizeOf,
+ &sizes, mRawSet.get());
+ aSizes.mLayoutServoStyleSetsStylistRuleTree +=
+ sizes.mStylistRuleTree;
+ aSizes.mLayoutServoStyleSetsStylistPrecomputedPseudos +=
+ sizes.mStylistPrecomputedPseudos;
+ aSizes.mLayoutServoStyleSetsStylistElementAndPseudosMaps +=
+ sizes.mStylistElementAndPseudosMaps;
+ aSizes.mLayoutServoStyleSetsStylistInvalidationMap +=
+ sizes.mStylistInvalidationMap;
+ aSizes.mLayoutServoStyleSetsStylistRevalidationSelectors +=
+ sizes.mStylistRevalidationSelectors;
+ aSizes.mLayoutServoStyleSetsStylistOther +=
+ sizes.mStylistOther;
+ aSizes.mLayoutServoStyleSetsOther +=
+ sizes.mOther;
}
if (mStyleRuleMap) {
aSizes.mLayoutServoStyleSetsOther +=
mStyleRuleMap->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
}
// Measurement of the following members may be added later if DMD finds it is
--- a/layout/style/ServoTypes.h
+++ b/layout/style/ServoTypes.h
@@ -197,20 +197,30 @@ struct ServoComputedValueFlags {
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
class ServoStyleSetSizes
{
public:
size_t mStylistRuleTree;
+ size_t mStylistPrecomputedPseudos;
+ size_t mStylistElementAndPseudosMaps;
+ size_t mStylistInvalidationMap;
+ size_t mStylistRevalidationSelectors;
+ size_t mStylistOther;
size_t mOther;
ServoStyleSetSizes()
: mStylistRuleTree(0)
+ , mStylistPrecomputedPseudos(0)
+ , mStylistElementAndPseudosMaps(0)
+ , mStylistInvalidationMap(0)
+ , mStylistRevalidationSelectors(0)
+ , mStylistOther(0)
, mOther(0)
{}
};
} // namespace mozilla
class ServoComputedData;