Bug 1396870 P1 Avoid dirting the image cache queue when inserting a new item into a clean queue. r=tnikkel
authorBen Kelly <ben@wanderview.com>
Tue, 05 Sep 2017 16:20:17 -0700
changeset 428612 c3218dfedd68920a8a33479c1a883042e9199d92
parent 428611 7b30671832a4ef163accb749f3d90f272e2004b0
child 428613 5ac7748ad699020b6f0cd9637ef281baf0c52558
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1396870
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 1396870 P1 Avoid dirting the image cache queue when inserting a new item into a clean queue. r=tnikkel
image/imgLoader.cpp
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -985,17 +985,21 @@ imgCacheQueue::Remove(imgCacheEntry* ent
 
 void
 imgCacheQueue::Push(imgCacheEntry* entry)
 {
   mSize += entry->GetDataSize();
 
   RefPtr<imgCacheEntry> refptr(entry);
   mQueue.push_back(refptr);
-  MarkDirty();
+  // If we're not dirty already, then we can efficiently add this to the
+  // binary heap immediately.  This is only O(log n).
+  if (!IsDirty()) {
+    std::push_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
+  }
 }
 
 already_AddRefed<imgCacheEntry>
 imgCacheQueue::Pop()
 {
   if (mQueue.empty()) {
     return nullptr;
   }
@@ -1009,16 +1013,18 @@ imgCacheQueue::Pop()
 
   mSize -= entry->GetDataSize();
   return entry.forget();
 }
 
 void
 imgCacheQueue::Refresh()
 {
+  // Resort the list.  This is an O(3 * n) operation and best avoided
+  // if possible.
   std::make_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
   mDirty = false;
 }
 
 void
 imgCacheQueue::MarkDirty()
 {
   mDirty = true;