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

Unified Diff: content/browser/indexed_db/leveldb/leveldb_database.cc

Issue 2760163002: [IndexedDB] Pool and evict leveldb iterators, to save memory (Closed)
Patch Set: 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
Index: content/browser/indexed_db/leveldb/leveldb_database.cc
diff --git a/content/browser/indexed_db/leveldb/leveldb_database.cc b/content/browser/indexed_db/leveldb/leveldb_database.cc
index 7eaa89405cb23782b5c070ca97947a64edb9f3ef..c521d33bb374ce2a317ebccc08b88a16d678ae0f 100644
--- a/content/browser/indexed_db/leveldb/leveldb_database.cc
+++ b/content/browser/indexed_db/leveldb/leveldb_database.cc
@@ -41,6 +41,7 @@
using base::StringPiece;
namespace content {
+static const size_t kMaxOpenIteratorsPerDatabase = 50;
jsbell 2017/03/21 00:15:48 We should get UMA stats on this. It may be that we
dmurph 2017/03/21 20:13:25 Hm... so I'll keep track of the max, and then repo
// Forcing flushes to disk at the end of a transaction guarantees that the
// data hit disk, but drastically impacts throughput when the filesystem is
@@ -92,7 +93,8 @@ LevelDBSnapshot::LevelDBSnapshot(LevelDBDatabase* db)
LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); }
-LevelDBDatabase::LevelDBDatabase() {}
+LevelDBDatabase::LevelDBDatabase()
+ : iterator_lru_(kMaxOpenIteratorsPerDatabase) {}
LevelDBDatabase::~LevelDBDatabase() {
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
@@ -479,4 +481,22 @@ bool LevelDBDatabase::OnMemoryDump(
return true;
}
+void LevelDBDatabase::NotifyIteratorUsed(LevelDBIterator* iter) {
+ if (iterator_lru_.size() == iterator_lru_.max_size()) {
+ auto to_evict_iter = iterator_lru_.rbegin();
+ LevelDBIterator* to_evict = to_evict_iter->first;
+ to_evict->EvictWorkingMemory();
+ iterator_lru_.Erase(to_evict_iter);
+ }
+ iterator_lru_.Put(iter, iter);
+}
+
+void LevelDBDatabase::NotifyIteratorDestroyed(LevelDBIterator* iter) {
+ auto it = iterator_lru_.Get(iter);
+ if (it == iterator_lru_.end()) {
jsbell 2017/03/21 00:15:48 nit: no need for {}
dmurph 2017/03/21 20:13:25 Done.
+ return;
+ }
+ iterator_lru_.Erase(it);
+ LOG(ERROR) << "iterator erased";
jsbell 2017/03/21 00:15:48 nit: obviously remove before landing. :)
dmurph 2017/03/21 20:13:25 Done.
+}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698