Changeset 183261 in webkit


Ignore:
Timestamp:
Apr 24, 2015 4:20:10 AM (9 years ago)
Author:
Antti Koivisto
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):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r183260 r183261  
     12015-04-24  Antti Koivisto  <antti@apple.com>
     2
     3        Memory cache live resources repeatedly purged during painting
     4        https://bugs.webkit.org/show_bug.cgi?id=144104
     5
     6        Reviewed by Chris Dumez.
     7
     8        * http/tests/cache/disk-cache/disk-cache-vary-cookie.html:
     9
     10            These clearMemoryCache calls are now done by cache-test.js.
     11
     12        * http/tests/cache/disk-cache/resources/cache-test.js:
     13        (loadResources):
     14
     15            Make sure to clear the memory cache explicitly in the beginning so we always hit the disk cache.
     16
     17        (runTests):
     18
    1192015-04-24  Antti Koivisto  <antti@apple.com>
    220
  • trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-vary-cookie.html

    r183260 r183261  
    1616loadResources(tests, function () {
    1717    printResults(tests);
    18     internals.clearMemoryCache();
    1918    debug("Loading again");
    2019    loadResources(tests, function () {
    2120        printResults(tests);
    22         internals.clearMemoryCache();
    2321        debug("Changing cookie and loading");
    2422        document.cookie = "cookie=othervalue";
    2523        loadResources(tests, function () {
    2624            printResults(tests);
    27             internals.clearMemoryCache()
    2825            debug("Loading again");
    2926            loadResources(tests, function () {
  • trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js

    r183260 r183261  
    7070function loadResources(tests, completetion)
    7171{
     72    // Otherwise we just get responses from the memory cache.
     73    internals.clearMemoryCache();
     74   
    7275    var pendingCount = tests.length;
    7376    for (var i = 0; i < tests.length; ++i) {
     
    98101{
    99102    loadResources(tests, function () {
    100         // Otherwise we just get responses from the memory cache.
    101         internals.clearMemoryCache();
    102103        // Wait a bit so things settle down in the disk cache.
    103104        setTimeout(function () {
  • trunk/Source/WebCore/ChangeLog

    r183260 r183261  
     12015-04-23  Antti Koivisto  <antti@apple.com>
     2
     3        Memory cache live resources repeatedly purged during painting
     4        https://bugs.webkit.org/show_bug.cgi?id=144104
     5        <rdar://problem/20667695>
     6
     7        Reviewed by Chris Dumez.
     8
     9        On some PLT pages (like nytimes.com) we get into state where painting repeatedly purges live bitmaps.
     10        This slows down page loads significantly.
     11
     12        This might have regressed because improvements in page caching keep more pages and so resources 'live'.
     13
     14        With this path we do all regular cache pruning asynchronously. If memory is really critical
     15        the low memory handling code will still prune synchronously.
     16
     17        * loader/cache/CachedResource.cpp:
     18        (WebCore::CachedResource::removeClient):
     19        (WebCore::CachedResource::didAccessDecodedData):
     20
     21            prune() -> pruneSoon()
     22
     23        * loader/cache/MemoryCache.cpp:
     24
     25            Decrease the pruning size target from 0.95 to 0.8 so we don't need to prune so often.
     26
     27        (WebCore::MemoryCache::needsPruning):
     28
     29            Factor into a function.
     30
     31        (WebCore::MemoryCache::prune):
     32        (WebCore::MemoryCache::pruneSoon):
     33
     34            Prune asynchronously.
     35
     36        * loader/cache/MemoryCache.h:
     37
    1382015-04-24  Antti Koivisto  <antti@apple.com>
    239
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r183260 r183261  
    461461            memoryCache.remove(*this);
    462462        }
    463         memoryCache.prune();
     463        memoryCache.pruneSoon();
    464464    }
    465465    // This object may be dead here.
     
    558558            memoryCache.insertInLiveDecodedResourcesList(*this);
    559559        }
    560         memoryCache.prune();
     560        memoryCache.pruneSoon();
    561561    }
    562562}
  • trunk/Source/WebCore/loader/cache/MemoryCache.cpp

    r183260 r183261  
    7070    , m_liveSize(0)
    7171    , m_deadSize(0)
     72    , m_pruneTimer(*this, &MemoryCache::pruneTimerFired)
    7273{
    7374}
     
    746747}
    747748
     749bool MemoryCache::needsPruning() const
     750{
     751    return m_liveSize + m_deadSize > m_capacity || m_deadSize > m_maxDeadCapacity;
     752}
     753
    748754void MemoryCache::prune()
    749755{
    750     if (m_liveSize + m_deadSize <= m_capacity && m_deadSize <= m_maxDeadCapacity) // Fast path.
     756    if (!needsPruning())
    751757        return;
    752758       
    753759    pruneDeadResources(); // Prune dead first, in case it was "borrowing" capacity from live.
    754760    pruneLiveResources();
     761}
     762
     763void MemoryCache::pruneTimerFired()
     764{
     765    prune();
     766}
     767
     768void MemoryCache::pruneSoon()
     769{
     770     if (m_pruneTimer.isActive())
     771        return;
     772     if (!needsPruning())
     773         return;
     774     m_pruneTimer.startOneShot(0);
    755775}
    756776
  • trunk/Source/WebCore/loader/cache/MemoryCache.h

    r183260 r183261  
    2929#include "SecurityOriginHash.h"
    3030#include "SessionID.h"
     31#include "Timer.h"
    3132#include <wtf/Forward.h>
    3233#include <wtf/HashMap.h>
     
    118119   
    119120    void prune();
     121    void pruneSoon();
    120122    unsigned size() const { return m_liveSize + m_deadSize; }
    121123
     
    185187    unsigned liveCapacity() const;
    186188    unsigned deadCapacity() const;
     189    bool needsPruning() const;
     190    void pruneTimerFired();
    187191
    188192    CachedResource* resourceForRequestImpl(const ResourceRequest&, CachedResourceMap&);
     
    214218    typedef HashMap<SessionID, std::unique_ptr<CachedResourceMap>> SessionCachedResourceMap;
    215219    SessionCachedResourceMap m_sessionResources;
     220
     221    Timer m_pruneTimer;
    216222};
    217223
Note: See TracChangeset for help on using the changeset viewer.