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

Unified Diff: cc/resources/resource_pool.cc

Issue 2726263003: cc::ResourcePool - Re-use larger resources for smaller requests (Closed)
Patch Set: build fix Created 3 years, 9 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
« no previous file with comments | « no previous file | cc/resources/resource_pool_unittest.cc » ('j') | 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 c2003758c4ba65ef0348e1988699c79f41dfb1b6..03779f823b3a4f102aac5108b302ae18968e6479 100644
--- a/cc/resources/resource_pool.cc
+++ b/cc/resources/resource_pool.cc
@@ -24,8 +24,30 @@ using base::trace_event::MemoryAllocatorDump;
using base::trace_event::MemoryDumpLevelOfDetail;
namespace cc {
+namespace {
+bool ResourceMeetsSizeRequirements(const gfx::Size& requested_size,
+ const gfx::Size& actual_size) {
+ const float kReuseScaleThreshold = 2.0f;
danakj 2017/03/10 16:32:12 driveby constant suggestion of something <= sqrt(2
ericrk 2017/03/10 18:44:20 I like limiting to 2x memory, but decided to go wi
+
+ // Allocating new resources is expensive, and we'd like to re-use our
+ // existing ones within reason. Allow a larger resource to be used for a
+ // smaller request.
+ if (actual_size.width() < requested_size.width() ||
+ actual_size.height() < requested_size.height())
+ return false;
+ // But don't use a resource that is more than |kReuseScaleThreshold| times
+ // the requested size, as we want to free unnecessarily large resources.
+ if (actual_size.width() > requested_size.width() * kReuseScaleThreshold ||
+ actual_size.height() > requested_size.height() * kReuseScaleThreshold)
+ return false;
+
+ return true;
+}
+
+} // namespace
+
base::TimeDelta ResourcePool::kDefaultExpirationDelay =
- base::TimeDelta::FromSeconds(1);
+ base::TimeDelta::FromSeconds(5);
ericrk 2017/03/10 01:51:14 Any number here is just a heuristic. 1 seemed to b
void ResourcePool::PoolResource::OnMemoryDump(
base::trace_event::ProcessMemoryDump* pmd,
@@ -119,7 +141,7 @@ Resource* ResourcePool::ReuseResource(const gfx::Size& size,
if (resource->format() != format)
continue;
- if (resource->size() != size)
+ if (!ResourceMeetsSizeRequirements(size, resource->size()))
continue;
if (resource->color_space() != color_space)
continue;
« no previous file with comments | « no previous file | cc/resources/resource_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698