Commit 5bfdef58 authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Reduce the write buffer for leveldb instances associated with Feed

I expect this to have a positive impact on Feed's memory usage.

Bug: 914597
Change-Id: I98b482fdbbf3f3a230902d7764cc32931c2c5784
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1749459
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686209}
parent 300d3fce
...@@ -24,8 +24,12 @@ namespace { ...@@ -24,8 +24,12 @@ namespace {
const char kContentDatabaseFolder[] = "content"; const char kContentDatabaseFolder[] = "content";
const size_t kDatabaseWriteBufferSizeBytes = 64 * 1024; // 64KB // Content writes vary a lot in size, loading full page will will have a couple
const size_t kDatabaseWriteBufferSizeBytesForLowEndDevice = 32 * 1024; // 32KB // dozen writes totaling a couple dozen KB, but there's a lot of variability.
// This should result in some batching while also keeping the memory impact very
// small.
const size_t kDatabaseWriteBufferSizeBytes = 8 * 1024; // 8KB
const size_t kDatabaseWriteBufferSizeBytesForLowEndDevice = 4 * 1024; // 4KB
leveldb::ReadOptions CreateReadOptions() { leveldb::ReadOptions CreateReadOptions() {
leveldb::ReadOptions opts; leveldb::ReadOptions opts;
......
...@@ -22,8 +22,9 @@ namespace { ...@@ -22,8 +22,9 @@ namespace {
const char kJournalDatabaseFolder[] = "journal"; const char kJournalDatabaseFolder[] = "journal";
const size_t kDatabaseWriteBufferSizeBytes = 64 * 1024; // 64KB // Journal updates happen infrequently and are typically ~8KB. However there's
const size_t kDatabaseWriteBufferSizeBytesForLowEndDevice = 32 * 1024; // 32KB // also one tiny write during startup before more writes that 1KB should handle.
const size_t kDatabaseWriteBufferSizeBytes = 1 * 1024; // 1KB
void ReportLoadTimeHistogram(bool success, base::TimeTicks start_time) { void ReportLoadTimeHistogram(bool success, base::TimeTicks start_time) {
base::TimeDelta load_time = base::TimeTicks::Now() - start_time; base::TimeDelta load_time = base::TimeTicks::Now() - start_time;
...@@ -69,9 +70,7 @@ bool FeedJournalDatabase::IsInitialized() const { ...@@ -69,9 +70,7 @@ bool FeedJournalDatabase::IsInitialized() const {
void FeedJournalDatabase::InitInternal() { void FeedJournalDatabase::InitInternal() {
leveldb_env::Options options = leveldb_proto::CreateSimpleOptions(); leveldb_env::Options options = leveldb_proto::CreateSimpleOptions();
options.write_buffer_size = base::SysInfo::IsLowEndDevice() options.write_buffer_size = kDatabaseWriteBufferSizeBytes;
? kDatabaseWriteBufferSizeBytesForLowEndDevice
: kDatabaseWriteBufferSizeBytes;
storage_database_->Init( storage_database_->Init(
options, base::BindOnce(&FeedJournalDatabase::OnDatabaseInitialized, options, base::BindOnce(&FeedJournalDatabase::OnDatabaseInitialized,
......
...@@ -36,10 +36,10 @@ int64_t ToDatabaseTime(base::Time time) { ...@@ -36,10 +36,10 @@ int64_t ToDatabaseTime(base::Time time) {
// The folder where the data will be stored on disk. // The folder where the data will be stored on disk.
const char kImageDatabaseFolder[] = "cached_image_fetcher_images"; const char kImageDatabaseFolder[] = "cached_image_fetcher_images";
// The amount of data to build up in memory before converting to a sorted on- // Most writes are very small, <100 bytes. This should buffer a handful of them
// disk file. // together, but not much more. This should allow a handful of them to be
const size_t kDatabaseWriteBufferSizeBytes = 64 * 1024; // 64KB // buffered together without causing a significant impact to memory.
const size_t kDatabaseWriteBufferSizeBytesForLowEndDevice = 32 * 1024; // 32KB const size_t kDatabaseWriteBufferSizeBytes = 1 * 1024; // 1KB
bool KeyMatcherFilter(std::string key, const std::string& other_key) { bool KeyMatcherFilter(std::string key, const std::string& other_key) {
return key.compare(other_key) == 0; return key.compare(other_key) == 0;
...@@ -80,11 +80,7 @@ ImageMetadataStoreLevelDB::~ImageMetadataStoreLevelDB() = default; ...@@ -80,11 +80,7 @@ ImageMetadataStoreLevelDB::~ImageMetadataStoreLevelDB() = default;
void ImageMetadataStoreLevelDB::Initialize(base::OnceClosure callback) { void ImageMetadataStoreLevelDB::Initialize(base::OnceClosure callback) {
leveldb_env::Options options = leveldb_proto::CreateSimpleOptions(); leveldb_env::Options options = leveldb_proto::CreateSimpleOptions();
if (base::SysInfo::IsLowEndDevice()) { options.write_buffer_size = kDatabaseWriteBufferSizeBytes;
options.write_buffer_size = kDatabaseWriteBufferSizeBytesForLowEndDevice;
} else {
options.write_buffer_size = kDatabaseWriteBufferSizeBytes;
}
database_->Init( database_->Init(
options, options,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment