Small CPU optimization to experimental range filters (#12893)

Summary:
By reusing an object that owns a vector. The vector allocation/sizing was substantial in a CPU profile.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/12893

Test Plan: existing tests

Reviewed By: jowlyzhang

Differential Revision: D60405139

Pulled By: pdillinger

fbshipit-source-id: 8bfbc07cd9b4829f2ac9015e90f2b4eba61fd984
This commit is contained in:
Peter Dillinger 2024-07-29 14:23:35 -07:00 committed by Facebook GitHub Bot
parent 24d86f7b41
commit 9058fd037c
2 changed files with 8 additions and 2 deletions

View File

@ -711,7 +711,7 @@ class SstQueryFilterConfigsManagerImpl : public SstQueryFilterConfigsManager {
uint64_t /*file_size*/) override {
// FIXME later: `key` might contain user timestamp. That should be
// exposed properly in a future update to TablePropertiesCollector
KeySegmentsExtractor::Result extracted;
extracted.Reset();
if (extractor) {
extractor->Extract(key, KeySegmentsExtractor::kFullUserKey, &extracted);
if (UNLIKELY(extracted.category >=
@ -750,7 +750,7 @@ class SstQueryFilterConfigsManagerImpl : public SstQueryFilterConfigsManager {
}
}
prev_key.assign(key.data(), key.size());
prev_extracted = std::move(extracted);
std::swap(prev_extracted, extracted);
first_key = false;
return Status::OK();
}
@ -859,6 +859,7 @@ class SstQueryFilterConfigsManagerImpl : public SstQueryFilterConfigsManager {
std::vector<std::shared_ptr<SstQueryFilterBuilder>> builders;
bool first_key = true;
std::string prev_key;
KeySegmentsExtractor::Result extracted;
KeySegmentsExtractor::Result prev_extracted;
KeySegmentsExtractor::KeyCategorySet categories_seen;
};

View File

@ -238,6 +238,11 @@ class KeySegmentsExtractor {
// determined by segment 0 in some way, often the first byte.) The enum
// scalar values do not need to be related to key order.
KeyCategory category = kDefaultCategory;
void Reset() {
segment_ends.clear();
category = kDefaultCategory;
}
};
virtual ~KeySegmentsExtractor() {}