Bug 1480146 - Add memory reporting for the inline style cache. r=heycam

MANUAL PUSH: Splitting a stack after the fact to avoid getting the main patch backed out due to talos timeouts.

Differential Revision: https://phabricator.services.mozilla.com/D41731
This commit is contained in:
Emilio Cobos Álvarez 2019-08-16 10:56:25 +00:00
parent b726907ec7
commit f1008a9300

View File

@ -469,6 +469,8 @@ struct Loader::Sheets {
// 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) {
@ -578,6 +580,39 @@ auto Loader::Sheets::Lookup(SheetLoadDataHashKey& aKey, bool aSyncLoad)
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 *
*************************/
@ -2440,28 +2475,16 @@ 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: