Changeset 183194 in webkit


Ignore:
Timestamp:
Apr 23, 2015 10:48:37 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
<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:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r183187 r183194  
     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-23  Eric Carlson  <eric.carlson@apple.com>
    239
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r182369 r183194  
    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

    r182449 r183194  
    4444#include <wtf/MathExtras.h>
    4545#include <wtf/NeverDestroyed.h>
     46#include <wtf/RunLoop.h>
    4647#include <wtf/TemporaryChange.h>
    4748#include <wtf/text/CString.h>
     
    5152static const int cDefaultCacheCapacity = 8192 * 1024;
    5253static const double cMinDelayBeforeLiveDecodedPrune = 1; // Seconds.
    53 static const float cTargetPrunePercentage = .95f; // Percentage of capacity toward which we prune, to avoid immediately pruning again.
     54static const float cTargetPrunePercentage = 0.8; // Percentage of capacity toward which we prune, to avoid immediately pruning again.
    5455static const auto defaultDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    5556
     
    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.
    751         return;
    752        
     756    if (!needsPruning())
     757        return;
     758
    753759    pruneDeadResources(); // Prune dead first, in case it was "borrowing" capacity from live.
    754760    pruneLiveResources();
     761}
     762
     763void MemoryCache::pruneSoon()
     764{
     765    if (m_willPruneSoon)
     766        return;
     767    if (!needsPruning())
     768        return;
     769
     770    m_willPruneSoon = true;
     771    RunLoop::main().dispatch([this] {
     772        prune();
     773        m_willPruneSoon = false;
     774    });
    755775}
    756776
  • trunk/Source/WebCore/loader/cache/MemoryCache.h

    r182449 r183194  
    116116    WEBCORE_EXPORT void evictResources();
    117117    WEBCORE_EXPORT void evictResources(SessionID);
    118    
     118
    119119    void prune();
     120    void pruneSoon();
    120121    unsigned size() const { return m_liveSize + m_deadSize; }
    121122
     
    185186    unsigned liveCapacity() const;
    186187    unsigned deadCapacity() const;
     188    bool needsPruning() const;
    187189
    188190    CachedResource* resourceForRequestImpl(const ResourceRequest&, CachedResourceMap&);
     
    214216    typedef HashMap<SessionID, std::unique_ptr<CachedResourceMap>> SessionCachedResourceMap;
    215217    SessionCachedResourceMap m_sessionResources;
     218
     219    bool m_willPruneSoon { false };
    216220};
    217221
Note: See TracChangeset for help on using the changeset viewer.