void MemoryCache::pruneLiveResources(bool shouldDestroyDecodedDataForAllLiveResources) { unsigned capacity = shouldDestroyDecodedDataForAllLiveResources ? 0 : liveCapacity(); if (capacity && m_liveSize <= capacity) return; unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. pruneLiveResourcesToSize(targetSize, shouldDestroyDecodedDataForAllLiveResources); }
void MemoryCache::pruneLiveResources() { if (!m_pruneEnabled) return; unsigned capacity = liveCapacity(); if (capacity && m_liveSize <= capacity) return; unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. pruneLiveResourcesToSize(targetSize); }
void MemoryCache::pruneLiveResources() { unsigned capacity = liveCapacity(); if (!m_liveSize || (capacity && m_liveSize <= capacity)) return; unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. double currentTime = FrameView::currentPaintTimeStamp(); if (!currentTime) // In case prune is called directly, outside of a Frame paint. currentTime = WTF::currentTime(); // Destroy any decoded data in live objects that we can. // Start from the tail, since this is the lowest priority // and least recently accessed of the objects. // The list might not be sorted by the m_lastDecodedAccessTime. The impact // of this weaker invariant is minor as the below if statement to check the // elapsedTime will evaluate to false as the currentTime will be a lot // greater than the current->m_lastDecodedAccessTime. // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 // Start pruning from the lowest priority list. for (int priority = Resource::CacheLiveResourcePriorityLow; priority <= Resource::CacheLiveResourcePriorityHigh; ++priority) { Resource* current = m_liveDecodedResources[priority].m_tail; while (current) { Resource* prev = current->m_prevInLiveResourcesList; ASSERT(current->hasClients()); if (current->isLoaded() && current->decodedSize()) { // Check to see if the remaining resources are too new to prune. double elapsedTime = currentTime - current->m_lastDecodedAccessTime; if (elapsedTime < m_delayBeforeLiveDecodedPrune) return; // Destroy our decoded data. This will remove us from // m_liveDecodedResources, and possibly move us to a different LRU // list in m_allResources. current->destroyDecodedData(); if (targetSize && m_liveSize <= targetSize) return; } current = prev; } } }
void MemoryCache::pruneLiveResources(PruneStrategy strategy) { ASSERT(!m_prunePending); size_t capacity = liveCapacity(); if (strategy == MaximalPrune) capacity = 0; if (!m_liveSize || (capacity && m_liveSize <= capacity)) return; size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. // Destroy any decoded data in live objects that we can. // Start from the tail, since this is the lowest priority // and least recently accessed of the objects. // The list might not be sorted by the m_lastDecodedFrameTimeStamp. The impact // of this weaker invariant is minor as the below if statement to check the // elapsedTime will evaluate to false as the current time will be a lot // greater than the current->m_lastDecodedFrameTimeStamp. // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 // Start pruning from the lowest priority list. for (int priority = MemoryCacheLiveResourcePriorityLow; priority <= MemoryCacheLiveResourcePriorityHigh; ++priority) { MemoryCacheEntry* current = m_liveDecodedResources[priority].m_tail; while (current) { MemoryCacheEntry* previous = current->m_previousInLiveResourcesList; ASSERT(current->m_resource->hasClients()); if (current->m_resource->isLoaded() && current->m_resource->decodedSize()) { // Check to see if the remaining resources are too new to prune. double elapsedTime = m_pruneFrameTimeStamp - current->m_lastDecodedAccessTime; if (strategy == AutomaticPrune && elapsedTime < m_delayBeforeLiveDecodedPrune) return; // Destroy our decoded data if possible. This will remove us // from m_liveDecodedResources, and possibly move us to a // different LRU list in m_allResources. current->m_resource->prune(); if (targetSize && m_liveSize <= targetSize) return; } current = previous; } } }