Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/core/fetch/MemoryCache.cpp

Issue 2326743003: Do not call MemoryCache::prune() when a client/observer is removed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove justReleasedResource Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 while (true) { 641 while (true) {
642 ResourceMap::iterator resourceIter = resources->begin(); 642 ResourceMap::iterator resourceIter = resources->begin();
643 if (resourceIter == resources->end()) 643 if (resourceIter == resources->end())
644 break; 644 break;
645 evict(resourceIter->value.get()); 645 evict(resourceIter->value.get());
646 } 646 }
647 m_resourceMaps.remove(resourceMapIter); 647 m_resourceMaps.remove(resourceMapIter);
648 } 648 }
649 } 649 }
650 650
651 void MemoryCache::prune(Resource* justReleasedResource) 651 void MemoryCache::prune()
652 { 652 {
653 TRACE_EVENT0("renderer", "MemoryCache::prune()"); 653 TRACE_EVENT0("renderer", "MemoryCache::prune()");
654 654
655 if (m_inPruneResources) 655 if (m_inPruneResources)
656 return; 656 return;
657 if (m_liveSize + m_deadSize <= m_capacity && m_maxDeadCapacity && m_deadSize <= m_maxDeadCapacity) // Fast path. 657 if (m_liveSize + m_deadSize <= m_capacity && m_maxDeadCapacity && m_deadSize <= m_maxDeadCapacity) // Fast path.
658 return; 658 return;
659 659
660 // To avoid burdening the current thread with repetitive pruning jobs, 660 // To avoid burdening the current thread with repetitive pruning jobs,
661 // pruning is postponed until the end of the current task. If it has 661 // pruning is postponed until the end of the current task. If it has
662 // been more than m_maxPruneDeferralDelay since the last prune, 662 // been more than m_maxPruneDeferralDelay since the last prune,
663 // then we prune immediately. 663 // then we prune immediately.
664 // If the current thread's run loop is not active, then pruning will happen 664 // If the current thread's run loop is not active, then pruning will happen
665 // immediately only if it has been over m_maxPruneDeferralDelay 665 // immediately only if it has been over m_maxPruneDeferralDelay
666 // since the last prune. 666 // since the last prune.
667 double currentTime = WTF::currentTime(); 667 double currentTime = WTF::currentTime();
668 if (m_prunePending) { 668 if (m_prunePending) {
669 if (currentTime - m_pruneTimeStamp >= m_maxPruneDeferralDelay) { 669 if (currentTime - m_pruneTimeStamp >= m_maxPruneDeferralDelay) {
670 pruneNow(currentTime, AutomaticPrune); 670 pruneNow(currentTime, AutomaticPrune);
671 } 671 }
672 } else { 672 } else {
673 if (currentTime - m_pruneTimeStamp >= m_maxPruneDeferralDelay) { 673 if (currentTime - m_pruneTimeStamp >= m_maxPruneDeferralDelay) {
674 pruneNow(currentTime, AutomaticPrune); // Delay exceeded, prune now. 674 pruneNow(currentTime, AutomaticPrune); // Delay exceeded, prune now.
675 } else { 675 } else {
676 // Defer. 676 // Defer.
677 Platform::current()->currentThread()->addTaskObserver(this); 677 Platform::current()->currentThread()->addTaskObserver(this);
678 m_prunePending = true; 678 m_prunePending = true;
679 } 679 }
680 } 680 }
681
682 if (m_prunePending && m_deadSize > m_maxDeferredPruneDeadCapacity && justRel easedResource) {
683 // The following eviction does not respect LRU order, but it can be done
684 // immediately in constant time, as opposed to pruneDeadResources, which
685 // we would rather defer because it is O(N), which would make tear-down of N
686 // objects O(N^2) if we pruned immediately. This immediate eviction is a
687 // safeguard against runaway memory consumption by dead resources
688 // while a prune is pending.
689 if (MemoryCacheEntry* entry = getEntryForResource(justReleasedResource))
690 evict(entry);
691
692 // As a last resort, prune immediately
693 if (m_deadSize > m_maxDeferredPruneDeadCapacity)
694 pruneNow(currentTime, AutomaticPrune);
695 }
696 } 681 }
697 682
698 void MemoryCache::willProcessTask() 683 void MemoryCache::willProcessTask()
699 { 684 {
700 } 685 }
701 686
702 void MemoryCache::didProcessTask() 687 void MemoryCache::didProcessTask()
703 { 688 {
704 // Perform deferred pruning 689 // Perform deferred pruning
705 DCHECK(m_prunePending); 690 DCHECK(m_prunePending);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) 752 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y)
768 { 753 {
769 MemoryCacheEntry* ex = getEntryForResource(x); 754 MemoryCacheEntry* ex = getEntryForResource(x);
770 MemoryCacheEntry* ey = getEntryForResource(y); 755 MemoryCacheEntry* ey = getEntryForResource(y);
771 DCHECK(ex); 756 DCHECK(ex);
772 DCHECK(ey); 757 DCHECK(ey);
773 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size()); 758 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size());
774 } 759 }
775 760
776 } // namespace blink 761 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MemoryCache.h ('k') | third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698