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

Unified Diff: cc/resources/resource_pool.cc

Issue 1420433009: cc: Keep most recently used resources at the front of resource queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected implementation. Created 5 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 side-by-side diff with in-line comments
Download patch
« cc/base/scoped_ptr_deque.h ('K') | « cc/resources/resource_pool.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/resource_pool.cc
diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc
index 835c37d6c32d9f23029bcfea419ad6f8f2b3f2fc..227fecf43b1ca51bf07a053094a17171ef909b15 100644
--- a/cc/resources/resource_pool.cc
+++ b/cc/resources/resource_pool.cc
@@ -91,8 +91,12 @@ ResourcePool::~ResourcePool() {
Resource* ResourcePool::AcquireResource(const gfx::Size& size,
ResourceFormat format) {
- for (ResourceDeque::iterator it = unused_resources_.begin();
- it != unused_resources_.end(); ++it) {
+ // Traverse the |unused_resources_| from rear end as MRU resources are
+ // held at the rear end of the queue. This touches LRU resources only if
+ // needed, which inreases possibility of expiring more LRU resources
+ // within kResourceExpirationDelayMs.
+ for (ResourceDeque::reverse_iterator it = unused_resources_.rbegin();
+ it != unused_resources_.rend(); ++it) {
ScopedResource* resource = *it;
DCHECK(resource_provider_->CanLockForWrite(resource->id()));
@@ -102,7 +106,7 @@ Resource* ResourcePool::AcquireResource(const gfx::Size& size,
continue;
// Transfer resource to |in_use_resources_|.
- in_use_resources_.set(resource->id(), unused_resources_.take(it));
+ in_use_resources_.set(resource->id(), unused_resources_.rtake(it));
in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
resource->size(), resource->format());
return resource;
@@ -130,18 +134,22 @@ Resource* ResourcePool::AcquireResource(const gfx::Size& size,
Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) {
reveman 2015/11/02 01:47:07 It shouldn't matter in what order we search the re
prashant.n 2015/11/02 04:07:20 Ahh! I missed one content id = one resource (next_
DCHECK(content_id);
- auto it = std::find_if(unused_resources_.begin(), unused_resources_.end(),
- [content_id](const PoolResource* pool_resource) {
- return pool_resource->content_id() == content_id;
- });
- if (it == unused_resources_.end())
+ // TODO(prashant.n): Move resource finding logic to common function.
reveman 2015/11/02 01:47:07 I don't see much duplication of resource finding l
prashant.n 2015/11/02 04:07:20 Yes most of the code in getting resource from unus
reveman 2015/11/02 04:32:59 Ok, feel free to put up a patch for that and I'll
+ ResourceDeque::reverse_iterator it = unused_resources_.rbegin();
+ for (; it != unused_resources_.rend(); ++it) {
+ PoolResource* pool_resource = *it;
+ if (pool_resource->content_id() != content_id)
+ continue;
+ }
+
+ if (it == unused_resources_.rend())
return nullptr;
Resource* resource = *it;
DCHECK(resource_provider_->CanLockForWrite(resource->id()));
// Transfer resource to |in_use_resources_|.
- in_use_resources_.set(resource->id(), unused_resources_.take(it));
+ in_use_resources_.set(resource->id(), unused_resources_.rtake(it));
in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
resource->size(), resource->format());
return resource;
« cc/base/scoped_ptr_deque.h ('K') | « cc/resources/resource_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698