- Revision
- 183261
- Author
- [email protected]
- Date
- 2015-04-24 04:20:10 -0700 (Fri, 24 Apr 2015)
Log Message
Memory cache live resources repeatedly purged during painting
https://bugs.webkit.org/show_bug.cgi?id=144104
Source/WebCore:
<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:
LayoutTests:
Reviewed by Chris Dumez.
* http/tests/cache/disk-cache/disk-cache-vary-cookie.html:
These clearMemoryCache calls are now done by cache-test.js.
* http/tests/cache/disk-cache/resources/cache-test.js:
(loadResources):
Make sure to clear the memory cache explicitly in the beginning so we always hit the disk cache.
(runTests):
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (183260 => 183261)
--- trunk/LayoutTests/ChangeLog 2015-04-24 11:16:34 UTC (rev 183260)
+++ trunk/LayoutTests/ChangeLog 2015-04-24 11:20:10 UTC (rev 183261)
@@ -1,5 +1,23 @@
2015-04-24 Antti Koivisto <[email protected]>
+ Memory cache live resources repeatedly purged during painting
+ https://bugs.webkit.org/show_bug.cgi?id=144104
+
+ Reviewed by Chris Dumez.
+
+ * http/tests/cache/disk-cache/disk-cache-vary-cookie.html:
+
+ These clearMemoryCache calls are now done by cache-test.js.
+
+ * http/tests/cache/disk-cache/resources/cache-test.js:
+ (loadResources):
+
+ Make sure to clear the memory cache explicitly in the beginning so we always hit the disk cache.
+
+ (runTests):
+
+2015-04-24 Antti Koivisto <[email protected]>
+
Unreviewed, rolling out r183259.
Wrong ChangeLog.
Modified: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-vary-cookie.html (183260 => 183261)
--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-vary-cookie.html 2015-04-24 11:16:34 UTC (rev 183260)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-vary-cookie.html 2015-04-24 11:20:10 UTC (rev 183261)
@@ -15,16 +15,13 @@
document.cookie = "cookie=value";
loadResources(tests, function () {
printResults(tests);
- internals.clearMemoryCache();
debug("Loading again");
loadResources(tests, function () {
printResults(tests);
- internals.clearMemoryCache();
debug("Changing cookie and loading");
document.cookie = "cookie=othervalue";
loadResources(tests, function () {
printResults(tests);
- internals.clearMemoryCache()
debug("Loading again");
loadResources(tests, function () {
printResults(tests);
Modified: trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js (183260 => 183261)
--- trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js 2015-04-24 11:16:34 UTC (rev 183260)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js 2015-04-24 11:20:10 UTC (rev 183261)
@@ -69,6 +69,9 @@
function loadResources(tests, completetion)
{
+ // Otherwise we just get responses from the memory cache.
+ internals.clearMemoryCache();
+
var pendingCount = tests.length;
for (var i = 0; i < tests.length; ++i) {
loadResource(tests[i], function (ev) {
@@ -97,8 +100,6 @@
function runTests(tests, completionHandler)
{
loadResources(tests, function () {
- // Otherwise we just get responses from the memory cache.
- internals.clearMemoryCache();
// Wait a bit so things settle down in the disk cache.
setTimeout(function () {
loadResources(tests, function () {
Modified: trunk/Source/WebCore/ChangeLog (183260 => 183261)
--- trunk/Source/WebCore/ChangeLog 2015-04-24 11:16:34 UTC (rev 183260)
+++ trunk/Source/WebCore/ChangeLog 2015-04-24 11:20:10 UTC (rev 183261)
@@ -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-24 Antti Koivisto <[email protected]>
Unreviewed, rolling out r183259.
Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (183260 => 183261)
--- trunk/Source/WebCore/loader/cache/CachedResource.cpp 2015-04-24 11:16:34 UTC (rev 183260)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp 2015-04-24 11:20:10 UTC (rev 183261)
@@ -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 (183260 => 183261)
--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2015-04-24 11:16:34 UTC (rev 183260)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2015-04-24 11:20:10 UTC (rev 183261)
@@ -69,6 +69,7 @@
, m_deadDecodedDataDeletionInterval(defaultDecodedDataDeletionInterval)
, m_liveSize(0)
, m_deadSize(0)
+ , m_pruneTimer(*this, &MemoryCache::pruneTimerFired)
{
}
@@ -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::pruneTimerFired()
+{
+ prune();
+}
+
+void MemoryCache::pruneSoon()
+{
+ if (m_pruneTimer.isActive())
+ return;
+ if (!needsPruning())
+ return;
+ m_pruneTimer.startOneShot(0);
+}
+
#ifndef NDEBUG
void MemoryCache::dumpStats()
{
Modified: trunk/Source/WebCore/loader/cache/MemoryCache.h (183260 => 183261)
--- trunk/Source/WebCore/loader/cache/MemoryCache.h 2015-04-24 11:16:34 UTC (rev 183260)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.h 2015-04-24 11:20:10 UTC (rev 183261)
@@ -28,6 +28,7 @@
#include "NativeImagePtr.h"
#include "SecurityOriginHash.h"
#include "SessionID.h"
+#include "Timer.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
@@ -117,6 +118,7 @@
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 +186,8 @@
unsigned liveCapacity() const;
unsigned deadCapacity() const;
+ bool needsPruning() const;
+ void pruneTimerFired();
CachedResource* resourceForRequestImpl(const ResourceRequest&, CachedResourceMap&);
@@ -213,6 +217,8 @@
// referenced by a Web page).
typedef HashMap<SessionID, std::unique_ptr<CachedResourceMap>> SessionCachedResourceMap;
SessionCachedResourceMap m_sessionResources;
+
+ Timer m_pruneTimer;
};
}