From beeee9dccc338ae7129016f2f2e17d2a40ecc5df Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Tue, 8 Apr 2014 11:06:39 -0700 Subject: [PATCH] Small speedup of CompactionFilterV2 Summary: ToString() is expensive. Profiling shows that most compaction threads are stuck in jemalloc, allocating a new string. This will help out a litte. Test Plan: make check Reviewers: haobo, danguo Reviewed By: danguo CC: leveldb Differential Revision: https://reviews.facebook.net/D17583 --- db/db_impl.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 98964d3c2..796b73547 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2961,9 +2961,9 @@ Status DBImpl::DoCompactionWork(CompactionState* compact, const SliceTransform* transformer = cfd->options()->compaction_filter_factory_v2->GetPrefixExtractor(); - std::string key_prefix = transformer->Transform(key).ToString(); + const auto key_prefix = transformer->Transform(key); if (!prefix_initialized) { - compact->cur_prefix_ = key_prefix; + compact->cur_prefix_ = key_prefix.ToString(); prefix_initialized = true; } if (!ParseInternalKey(key, &ikey)) { @@ -2973,7 +2973,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact, continue; } else { // If the prefix remains the same, keep buffering - if (key_prefix == compact->cur_prefix_) { + if (key_prefix.compare(Slice(compact->cur_prefix_)) == 0) { // Apply the compaction filter V2 to all the kv pairs sharing // the same prefix if (ikey.type == kTypeValue && @@ -2994,7 +2994,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact, if (compact->key_buf_.size() > 0) { CallCompactionFilterV2(compact, compaction_filter_v2); } - compact->cur_prefix_ = key_prefix; + compact->cur_prefix_ = key_prefix.ToString(); } } -- GitLab