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

Side by Side Diff: Source/platform/graphics/ImageDecodingStore.cpp

Issue 110273002: Refine memory accounting in ImageDecodingStore for discardable entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Store accounting information in CacheEntry Created 7 years 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
« no previous file with comments | « Source/platform/graphics/ImageDecodingStore.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 14 matching lines...) Expand all
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "platform/graphics/ImageDecodingStore.h" 27 #include "platform/graphics/ImageDecodingStore.h"
28 28
29 #include "platform/TraceEvent.h" 29 #include "platform/TraceEvent.h"
30 30
31 namespace WebCore { 31 namespace WebCore {
32 32
33 namespace { 33 namespace {
34 34
35 // Allow up to 128 non-accounted discardable entries. Non-accounted entries are
36 // entries that do not contribute to the memory usage of the cache.
37 static const size_t maxNonAccountedDiscardableEntries = 128;
35 // 32MB memory limit for cache. 38 // 32MB memory limit for cache.
36 static const size_t defaultCacheLimitInBytes = 32768 * 1024; 39 static const size_t defaultCacheLimitInBytes = 32768 * 1024;
37 static ImageDecodingStore* s_instance = 0; 40 static ImageDecodingStore* s_instance = 0;
38 static bool s_imageCachingEnabled = true; 41 static bool s_imageCachingEnabled = true;
39 42
40 static void setInstance(ImageDecodingStore* imageDecodingStore) 43 static void setInstance(ImageDecodingStore* imageDecodingStore)
41 { 44 {
42 delete s_instance; 45 delete s_instance;
43 s_instance = imageDecodingStore; 46 s_instance = imageDecodingStore;
44 } 47 }
45 48
46 } // namespace 49 } // namespace
47 50
48 ImageDecodingStore::ImageDecodingStore() 51 ImageDecodingStore::ImageDecodingStore()
49 : m_cacheLimitInBytes(defaultCacheLimitInBytes) 52 : m_discardableEntriesCount(0)
53 , m_cacheLimitInBytes(defaultCacheLimitInBytes)
50 , m_memoryUsageInBytes(0) 54 , m_memoryUsageInBytes(0)
51 { 55 {
52 } 56 }
53 57
54 ImageDecodingStore::~ImageDecodingStore() 58 ImageDecodingStore::~ImageDecodingStore()
55 { 59 {
56 #ifndef NDEBUG 60 #ifndef NDEBUG
57 setCacheLimitInBytes(0); 61 setCacheLimitInBytes(0);
58 ASSERT(!m_imageCacheMap.size()); 62 ASSERT(!m_imageCacheMap.size());
59 ASSERT(!m_decoderCacheMap.size()); 63 ASSERT(!m_decoderCacheMap.size());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 return false; 342 return false;
339 } 343 }
340 cacheEntry->incrementUseCount(); 344 cacheEntry->incrementUseCount();
341 *cachedImage = image; 345 *cachedImage = image;
342 return true; 346 return true;
343 } 347 }
344 348
345 template<class T, class U, class V> 349 template<class T, class U, class V>
346 void ImageDecodingStore::insertCacheInternal(PassOwnPtr<T> cacheEntry, U* cacheM ap, V* identifierMap) 350 void ImageDecodingStore::insertCacheInternal(PassOwnPtr<T> cacheEntry, U* cacheM ap, V* identifierMap)
347 { 351 {
348 // Usage of discardable memory is not counted because we want to use more 352 if (cacheEntry->isDiscardable()) {
349 // than the cache limit allows. Cache limit only applies to non-discardable 353 ++m_discardableEntriesCount;
350 // objects. 354 if (m_discardableEntriesCount <= maxNonAccountedDiscardableEntries)
351 if (!cacheEntry->isDiscardable()) 355 cacheEntry->disableAccounting();
356 }
357 if (cacheEntry->isAccountingEnabled())
352 incrementMemoryUsage(cacheEntry->memoryUsageInBytes()); 358 incrementMemoryUsage(cacheEntry->memoryUsageInBytes());
353 359
354 // m_orderedCacheList is used to support LRU operations to reorder cache 360 // m_orderedCacheList is used to support LRU operations to reorder cache
355 // entries quickly. 361 // entries quickly.
356 m_orderedCacheList.append(cacheEntry.get()); 362 m_orderedCacheList.append(cacheEntry.get());
357 363
358 typename U::KeyType key = cacheEntry->cacheKey(); 364 typename U::KeyType key = cacheEntry->cacheKey();
359 typename V::AddResult result = identifierMap->add(cacheEntry->generator(), t ypename V::MappedType()); 365 typename V::AddResult result = identifierMap->add(cacheEntry->generator(), t ypename V::MappedType());
360 result.iterator->value.add(key); 366 result.iterator->value.add(key);
361 cacheMap->add(key, cacheEntry); 367 cacheMap->add(key, cacheEntry);
362 368
363 TRACE_COUNTER1("webkit", "ImageDecodingStoreMemoryUsageBytes", m_memoryUsage InBytes); 369 TRACE_COUNTER1("webkit", "ImageDecodingStoreMemoryUsageBytes", m_memoryUsage InBytes);
364 TRACE_COUNTER1("webkit", "ImageDecodingStoreNumOfImages", m_imageCacheMap.si ze()); 370 TRACE_COUNTER1("webkit", "ImageDecodingStoreNumOfImages", m_imageCacheMap.si ze());
365 TRACE_COUNTER1("webkit", "ImageDecodingStoreNumOfDecoders", m_decoderCacheMa p.size()); 371 TRACE_COUNTER1("webkit", "ImageDecodingStoreNumOfDecoders", m_decoderCacheMa p.size());
366 } 372 }
367 373
368 template<class T, class U, class V> 374 template<class T, class U, class V>
369 void ImageDecodingStore::removeFromCacheInternal(const T* cacheEntry, U* cacheMa p, V* identifierMap, Vector<OwnPtr<CacheEntry> >* deletionList) 375 void ImageDecodingStore::removeFromCacheInternal(const T* cacheEntry, U* cacheMa p, V* identifierMap, Vector<OwnPtr<CacheEntry> >* deletionList)
370 { 376 {
371 if (!cacheEntry->isDiscardable()) 377 if (cacheEntry->isDiscardable()) {
378 ASSERT(m_discardableEntriesCount > 0);
379 --m_discardableEntriesCount;
380 }
381 if (cacheEntry->isAccountingEnabled())
372 decrementMemoryUsage(cacheEntry->memoryUsageInBytes()); 382 decrementMemoryUsage(cacheEntry->memoryUsageInBytes());
373 383
374 // Remove entry from identifier map. 384 // Remove entry from identifier map.
375 typename V::iterator iter = identifierMap->find(cacheEntry->generator()); 385 typename V::iterator iter = identifierMap->find(cacheEntry->generator());
376 ASSERT(iter != identifierMap->end()); 386 ASSERT(iter != identifierMap->end());
377 iter->value.remove(cacheEntry->cacheKey()); 387 iter->value.remove(cacheEntry->cacheKey());
378 if (!iter->value.size()) 388 if (!iter->value.size())
379 identifierMap->remove(iter); 389 identifierMap->remove(iter);
380 390
381 // Remove entry from cache map. 391 // Remove entry from cache map.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 427 }
418 } 428 }
419 429
420 void ImageDecodingStore::removeFromCacheListInternal(const Vector<OwnPtr<CacheEn try> >& deletionList) 430 void ImageDecodingStore::removeFromCacheListInternal(const Vector<OwnPtr<CacheEn try> >& deletionList)
421 { 431 {
422 for (size_t i = 0; i < deletionList.size(); ++i) 432 for (size_t i = 0; i < deletionList.size(); ++i)
423 m_orderedCacheList.remove(deletionList[i].get()); 433 m_orderedCacheList.remove(deletionList[i].get());
424 } 434 }
425 435
426 } // namespace WebCore 436 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/graphics/ImageDecodingStore.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698