improve-histogram-performance: remove valueIndexMap_ (#8625)
Summary: `valueIndexMap_` in histogram is redundant and search in `valueIndexMap_` is slower than search in `bucketValues_`. this PR delete `valueIndexMap_` and search in `bucketValues_` by `std::lower_bound` Pull Request resolved: https://github.com/facebook/rocksdb/pull/8625 Reviewed By: zhichao-cao Differential Revision: D31613386 Pulled By: ajkr fbshipit-source-id: d7415d724f5c8f41f80cbe82afd7467cfad6f009
This commit is contained in:
parent
c246c9c6e2
commit
97b30dee5b
@ -10,6 +10,8 @@
|
||||
#include "monitoring/histogram.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
@ -23,7 +25,6 @@ HistogramBucketMapper::HistogramBucketMapper() {
|
||||
// If you change this, you also need to change
|
||||
// size of array buckets_ in HistogramImpl
|
||||
bucketValues_ = {1, 2};
|
||||
valueIndexMap_ = {{1, 0}, {2, 1}};
|
||||
double bucket_val = static_cast<double>(bucketValues_.back());
|
||||
while ((bucket_val = 1.5 * bucket_val) <= static_cast<double>(port::kMaxUint64)) {
|
||||
bucketValues_.push_back(static_cast<uint64_t>(bucket_val));
|
||||
@ -35,26 +36,18 @@ HistogramBucketMapper::HistogramBucketMapper() {
|
||||
pow_of_ten *= 10;
|
||||
}
|
||||
bucketValues_.back() *= pow_of_ten;
|
||||
valueIndexMap_[bucketValues_.back()] = bucketValues_.size() - 1;
|
||||
}
|
||||
maxBucketValue_ = bucketValues_.back();
|
||||
minBucketValue_ = bucketValues_.front();
|
||||
}
|
||||
|
||||
size_t HistogramBucketMapper::IndexForValue(const uint64_t value) const {
|
||||
if (value >= maxBucketValue_) {
|
||||
return bucketValues_.size() - 1;
|
||||
} else if ( value >= minBucketValue_ ) {
|
||||
std::map<uint64_t, uint64_t>::const_iterator lowerBound =
|
||||
valueIndexMap_.lower_bound(value);
|
||||
if (lowerBound != valueIndexMap_.end()) {
|
||||
return static_cast<size_t>(lowerBound->second);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
auto beg = bucketValues_.begin();
|
||||
auto end = bucketValues_.end();
|
||||
if (value >= maxBucketValue_)
|
||||
return end - beg - 1; // bucketValues_.size() - 1
|
||||
else
|
||||
return std::lower_bound(beg, end, value) - beg;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -48,7 +48,6 @@ class HistogramBucketMapper {
|
||||
std::vector<uint64_t> bucketValues_;
|
||||
uint64_t maxBucketValue_;
|
||||
uint64_t minBucketValue_;
|
||||
std::map<uint64_t, uint64_t> valueIndexMap_;
|
||||
};
|
||||
|
||||
struct HistogramStat {
|
||||
|
Loading…
x
Reference in New Issue
Block a user