Title: [183194] trunk/Source/WebCore
- Revision
- 183194
- Author
- [email protected]
- Date
- 2015-04-23 10:48:37 -0700 (Thu, 23 Apr 2015)
Log Message
Memory cache live resources repeatedly purged during painting
https://bugs.webkit.org/show_bug.cgi?id=144104
<rdar://problem/20667695>
Reviewed by Chris Dumez.
On some PLT pages (like nytimes.com) we get into state where painting repeatedly purges live bitmaps.
This slows down page loads significantly.
This might have regressed because improvements in page caching keep more pages and so resources 'live'.
With this path we do all regular cache pruning asynchronously. If memory is really critical
the low memory handling code will still prune synchronously.
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::removeClient):
(WebCore::CachedResource::didAccessDecodedData):
prune() -> pruneSoon()
* loader/cache/MemoryCache.cpp:
Decrease the pruning size target from 0.95 to 0.8 so we don't need to prune so often.
(WebCore::MemoryCache::needsPruning):
Factor into a function.
(WebCore::MemoryCache::prune):
(WebCore::MemoryCache::pruneSoon):
Prune asynchronously.
* loader/cache/MemoryCache.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (183193 => 183194)
--- trunk/Source/WebCore/ChangeLog 2015-04-23 17:31:30 UTC (rev 183193)
+++ trunk/Source/WebCore/ChangeLog 2015-04-23 17:48:37 UTC (rev 183194)
@@ -1,3 +1,40 @@
+2015-04-23 Antti Koivisto <[email protected]>
+
+ Memory cache live resources repeatedly purged during painting
+ https://bugs.webkit.org/show_bug.cgi?id=144104
+ <rdar://problem/20667695>
+
+ Reviewed by Chris Dumez.
+
+ On some PLT pages (like nytimes.com) we get into state where painting repeatedly purges live bitmaps.
+ This slows down page loads significantly.
+
+ This might have regressed because improvements in page caching keep more pages and so resources 'live'.
+
+ With this path we do all regular cache pruning asynchronously. If memory is really critical
+ the low memory handling code will still prune synchronously.
+
+ * loader/cache/CachedResource.cpp:
+ (WebCore::CachedResource::removeClient):
+ (WebCore::CachedResource::didAccessDecodedData):
+
+ prune() -> pruneSoon()
+
+ * loader/cache/MemoryCache.cpp:
+
+ Decrease the pruning size target from 0.95 to 0.8 so we don't need to prune so often.
+
+ (WebCore::MemoryCache::needsPruning):
+
+ Factor into a function.
+
+ (WebCore::MemoryCache::prune):
+ (WebCore::MemoryCache::pruneSoon):
+
+ Prune asynchronously.
+
+ * loader/cache/MemoryCache.h:
+
2015-04-23 Eric Carlson <[email protected]>
Unreviewed, make a suggested change I overlooked in Darin's review of
Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (183193 => 183194)
--- trunk/Source/WebCore/loader/cache/CachedResource.cpp 2015-04-23 17:31:30 UTC (rev 183193)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp 2015-04-23 17:48:37 UTC (rev 183194)
@@ -460,7 +460,7 @@
// We allow non-secure content to be reused in history, but we do not allow secure content to be reused.
memoryCache.remove(*this);
}
- memoryCache.prune();
+ memoryCache.pruneSoon();
}
// This object may be dead here.
}
@@ -557,7 +557,7 @@
memoryCache.removeFromLiveDecodedResourcesList(*this);
memoryCache.insertInLiveDecodedResourcesList(*this);
}
- memoryCache.prune();
+ memoryCache.pruneSoon();
}
}
Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (183193 => 183194)
--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2015-04-23 17:31:30 UTC (rev 183193)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2015-04-23 17:48:37 UTC (rev 183194)
@@ -43,6 +43,7 @@
#include <wtf/CurrentTime.h>
#include <wtf/MathExtras.h>
#include <wtf/NeverDestroyed.h>
+#include <wtf/RunLoop.h>
#include <wtf/TemporaryChange.h>
#include <wtf/text/CString.h>
@@ -50,7 +51,7 @@
static const int cDefaultCacheCapacity = 8192 * 1024;
static const double cMinDelayBeforeLiveDecodedPrune = 1; // Seconds.
-static const float cTargetPrunePercentage = .95f; // Percentage of capacity toward which we prune, to avoid immediately pruning again.
+static const float cTargetPrunePercentage = 0.8; // Percentage of capacity toward which we prune, to avoid immediately pruning again.
static const auto defaultDecodedDataDeletionInterval = std::chrono::seconds { 0 };
MemoryCache& MemoryCache::singleton()
@@ -745,15 +746,34 @@
ASSERT(!m_sessionResources.contains(sessionID));
}
+bool MemoryCache::needsPruning() const
+{
+ return m_liveSize + m_deadSize > m_capacity || m_deadSize > m_maxDeadCapacity;
+}
+
void MemoryCache::prune()
{
- if (m_liveSize + m_deadSize <= m_capacity && m_deadSize <= m_maxDeadCapacity) // Fast path.
+ if (!needsPruning())
return;
-
+
pruneDeadResources(); // Prune dead first, in case it was "borrowing" capacity from live.
pruneLiveResources();
}
+void MemoryCache::pruneSoon()
+{
+ if (m_willPruneSoon)
+ return;
+ if (!needsPruning())
+ return;
+
+ m_willPruneSoon = true;
+ RunLoop::main().dispatch([this] {
+ prune();
+ m_willPruneSoon = false;
+ });
+}
+
#ifndef NDEBUG
void MemoryCache::dumpStats()
{
Modified: trunk/Source/WebCore/loader/cache/MemoryCache.h (183193 => 183194)
--- trunk/Source/WebCore/loader/cache/MemoryCache.h 2015-04-23 17:31:30 UTC (rev 183193)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.h 2015-04-23 17:48:37 UTC (rev 183194)
@@ -115,8 +115,9 @@
WEBCORE_EXPORT void evictResources();
WEBCORE_EXPORT void evictResources(SessionID);
-
+
void prune();
+ void pruneSoon();
unsigned size() const { return m_liveSize + m_deadSize; }
void setDeadDecodedDataDeletionInterval(std::chrono::milliseconds interval) { m_deadDecodedDataDeletionInterval = interval; }
@@ -184,6 +185,7 @@
unsigned liveCapacity() const;
unsigned deadCapacity() const;
+ bool needsPruning() const;
CachedResource* resourceForRequestImpl(const ResourceRequest&, CachedResourceMap&);
@@ -213,6 +215,8 @@
// referenced by a Web page).
typedef HashMap<SessionID, std::unique_ptr<CachedResourceMap>> SessionCachedResourceMap;
SessionCachedResourceMap m_sessionResources;
+
+ bool m_willPruneSoon { false };
};
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes