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
This commit is contained in:
parent
92c1eb0291
commit
beeee9dccc
@ -2961,9 +2961,9 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
|
|||||||
|
|
||||||
const SliceTransform* transformer =
|
const SliceTransform* transformer =
|
||||||
cfd->options()->compaction_filter_factory_v2->GetPrefixExtractor();
|
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) {
|
if (!prefix_initialized) {
|
||||||
compact->cur_prefix_ = key_prefix;
|
compact->cur_prefix_ = key_prefix.ToString();
|
||||||
prefix_initialized = true;
|
prefix_initialized = true;
|
||||||
}
|
}
|
||||||
if (!ParseInternalKey(key, &ikey)) {
|
if (!ParseInternalKey(key, &ikey)) {
|
||||||
@ -2973,7 +2973,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// If the prefix remains the same, keep buffering
|
// 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
|
// Apply the compaction filter V2 to all the kv pairs sharing
|
||||||
// the same prefix
|
// the same prefix
|
||||||
if (ikey.type == kTypeValue &&
|
if (ikey.type == kTypeValue &&
|
||||||
@ -2994,7 +2994,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
|
|||||||
if (compact->key_buf_.size() > 0) {
|
if (compact->key_buf_.size() > 0) {
|
||||||
CallCompactionFilterV2(compact, compaction_filter_v2);
|
CallCompactionFilterV2(compact, compaction_filter_v2);
|
||||||
}
|
}
|
||||||
compact->cur_prefix_ = key_prefix;
|
compact->cur_prefix_ = key_prefix.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user