From 33344c644565da249697e265c48c4262329c8e66 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Sun, 9 Jul 2017 17:49:10 -0700 Subject: [PATCH] #415: M1376936 M1375331 --- dom/base/nsContentList.cpp | 14 +++++++++++++- dom/base/nsContentList.h | 5 +++++ layout/base/nsPresArena.cpp | 12 ++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/dom/base/nsContentList.cpp b/dom/base/nsContentList.cpp index dbf0fb29d..abf7df69d 100644 --- a/dom/base/nsContentList.cpp +++ b/dom/base/nsContentList.cpp @@ -92,7 +92,8 @@ NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTING_ADDREF(nsBaseContentList) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsBaseContentList) +NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsBaseContentList, + LastRelease()) NS_IMETHODIMP @@ -612,6 +613,17 @@ nsContentList::NodeWillBeDestroyed(const nsINode* aNode) SetDirty(); } +void +nsContentList::LastRelease() +{ + RemoveFromCaches(); + if (mRootNode) { + mRootNode->RemoveMutationObserver(this); + mRootNode = nullptr; + } + SetDirty(); +} + NS_IMETHODIMP nsContentList::GetLength(uint32_t* aLength) { diff --git a/dom/base/nsContentList.h b/dom/base/nsContentList.h index 1c57fb698..7a34700b5 100644 --- a/dom/base/nsContentList.h +++ b/dom/base/nsContentList.h @@ -95,6 +95,9 @@ public: { mElements.SetCapacity(aCapacity); } + + virtual void LastRelease() {} + protected: virtual ~nsBaseContentList(); @@ -348,6 +351,8 @@ public: Reset(); } + virtual void LastRelease() override; + protected: /** * Returns whether the element matches our criterion diff --git a/layout/base/nsPresArena.cpp b/layout/base/nsPresArena.cpp index 2b1f072df..5000422b3 100644 --- a/layout/base/nsPresArena.cpp +++ b/layout/base/nsPresArena.cpp @@ -131,9 +131,17 @@ nsPresArena::Allocate(uint32_t aCode, size_t aSize) void* result; if (len > 0) { - // LIFO behavior for best cache utilization + // Remove from the end of the mEntries array to avoid memmoving entries, + // and use SetLengthAndRetainStorage to avoid a lot of malloc/free + // from ShrinkCapacity on smaller sizes. 500 pointers means the malloc size + // for the array is 4096 bytes or more on a 64-bit system. The next smaller + // size is 2048 (with jemalloc), which we consider not worth compacting. result = list->mEntries.ElementAt(len - 1); - list->mEntries.RemoveElementAt(len - 1); + if (list->mEntries.Capacity() > 500) { + list->mEntries.RemoveElementAt(len - 1); + } else { + list->mEntries.SetLengthAndRetainStorage(len - 1); + } #if defined(DEBUG) { MOZ_MAKE_MEM_DEFINED(result, list->mEntrySize);