Imporve perf of random read and insert compare by suggesting inlining to the compiler
Summary: Results from 2015 compiler. This improve sequential insert. Random Read results are inconclusive but I hope 2017 will do a better job at inlining. Before: fillseq : **3.638 micros/op 274866 ops/sec; 213.9 MB/s** After: fillseq : **3.379 micros/op 295979 ops/sec; 230.3 MB/s** Closes https://github.com/facebook/rocksdb/pull/3645 Differential Revision: D7382711 Pulled By: siying fbshipit-source-id: 092a07ffe8a6e598d1226ceff0f11b35e6c5c8e4
This commit is contained in:
parent
53d66df0c4
commit
d382ae7de6
@ -106,45 +106,6 @@ const char* InternalKeyComparator::Name() const {
|
|||||||
return name_.c_str();
|
return name_.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int InternalKeyComparator::Compare(const Slice& akey, const Slice& bkey) const {
|
|
||||||
// Order by:
|
|
||||||
// increasing user key (according to user-supplied comparator)
|
|
||||||
// decreasing sequence number
|
|
||||||
// decreasing type (though sequence# should be enough to disambiguate)
|
|
||||||
int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey));
|
|
||||||
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
|
||||||
if (r == 0) {
|
|
||||||
const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8);
|
|
||||||
const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8);
|
|
||||||
if (anum > bnum) {
|
|
||||||
r = -1;
|
|
||||||
} else if (anum < bnum) {
|
|
||||||
r = +1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int InternalKeyComparator::CompareKeySeq(const Slice& akey,
|
|
||||||
const Slice& bkey) const {
|
|
||||||
// Order by:
|
|
||||||
// increasing user key (according to user-supplied comparator)
|
|
||||||
// decreasing sequence number
|
|
||||||
int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey));
|
|
||||||
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
|
||||||
if (r == 0) {
|
|
||||||
// Shift the number to exclude the last byte which contains the value type
|
|
||||||
const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8) >> 8;
|
|
||||||
const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8) >> 8;
|
|
||||||
if (anum > bnum) {
|
|
||||||
r = -1;
|
|
||||||
} else if (anum < bnum) {
|
|
||||||
r = +1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int InternalKeyComparator::Compare(const ParsedInternalKey& a,
|
int InternalKeyComparator::Compare(const ParsedInternalKey& a,
|
||||||
const ParsedInternalKey& b) const {
|
const ParsedInternalKey& b) const {
|
||||||
// Order by:
|
// Order by:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include "monitoring/perf_context_imp.h"
|
||||||
#include "rocksdb/comparator.h"
|
#include "rocksdb/comparator.h"
|
||||||
#include "rocksdb/db.h"
|
#include "rocksdb/db.h"
|
||||||
#include "rocksdb/filter_policy.h"
|
#include "rocksdb/filter_policy.h"
|
||||||
@ -607,4 +608,46 @@ struct RangeTombstone {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline
|
||||||
|
int InternalKeyComparator::Compare(const Slice& akey, const Slice& bkey) const {
|
||||||
|
// Order by:
|
||||||
|
// increasing user key (according to user-supplied comparator)
|
||||||
|
// decreasing sequence number
|
||||||
|
// decreasing type (though sequence# should be enough to disambiguate)
|
||||||
|
int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey));
|
||||||
|
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
||||||
|
if (r == 0) {
|
||||||
|
const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8);
|
||||||
|
const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8);
|
||||||
|
if (anum > bnum) {
|
||||||
|
r = -1;
|
||||||
|
} else if (anum < bnum) {
|
||||||
|
r = +1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int InternalKeyComparator::CompareKeySeq(const Slice& akey,
|
||||||
|
const Slice& bkey) const {
|
||||||
|
// Order by:
|
||||||
|
// increasing user key (according to user-supplied comparator)
|
||||||
|
// decreasing sequence number
|
||||||
|
int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey));
|
||||||
|
PERF_COUNTER_ADD(user_key_comparison_count, 1);
|
||||||
|
if (r == 0) {
|
||||||
|
// Shift the number to exclude the last byte which contains the value type
|
||||||
|
const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8) >> 8;
|
||||||
|
const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8) >> 8;
|
||||||
|
if (anum > bnum) {
|
||||||
|
r = -1;
|
||||||
|
} else if (anum < bnum) {
|
||||||
|
r = +1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
namespace rocksdb {
|
namespace rocksdb {
|
||||||
|
|
||||||
|
inline
|
||||||
void BlockFetcher::CheckBlockChecksum() {
|
void BlockFetcher::CheckBlockChecksum() {
|
||||||
// Check the crc of the type and the block contents
|
// Check the crc of the type and the block contents
|
||||||
if (read_options_.verify_checksums) {
|
if (read_options_.verify_checksums) {
|
||||||
@ -62,6 +63,7 @@ void BlockFetcher::CheckBlockChecksum() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() {
|
bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() {
|
||||||
if (cache_options_.persistent_cache &&
|
if (cache_options_.persistent_cache &&
|
||||||
!cache_options_.persistent_cache->IsCompressed()) {
|
!cache_options_.persistent_cache->IsCompressed()) {
|
||||||
@ -83,6 +85,7 @@ bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
bool BlockFetcher::TryGetFromPrefetchBuffer() {
|
bool BlockFetcher::TryGetFromPrefetchBuffer() {
|
||||||
if (prefetch_buffer_ != nullptr &&
|
if (prefetch_buffer_ != nullptr &&
|
||||||
prefetch_buffer_->TryReadFromCache(
|
prefetch_buffer_->TryReadFromCache(
|
||||||
@ -99,6 +102,7 @@ bool BlockFetcher::TryGetFromPrefetchBuffer() {
|
|||||||
return got_from_prefetch_buffer_;
|
return got_from_prefetch_buffer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() {
|
bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() {
|
||||||
if (cache_options_.persistent_cache &&
|
if (cache_options_.persistent_cache &&
|
||||||
cache_options_.persistent_cache->IsCompressed()) {
|
cache_options_.persistent_cache->IsCompressed()) {
|
||||||
@ -119,6 +123,7 @@ bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
void BlockFetcher::PrepareBufferForBlockFromFile() {
|
void BlockFetcher::PrepareBufferForBlockFromFile() {
|
||||||
// cache miss read from device
|
// cache miss read from device
|
||||||
if (do_uncompress_ &&
|
if (do_uncompress_ &&
|
||||||
@ -127,12 +132,12 @@ void BlockFetcher::PrepareBufferForBlockFromFile() {
|
|||||||
// trivially allocated stack buffer instead of needing a full malloc()
|
// trivially allocated stack buffer instead of needing a full malloc()
|
||||||
used_buf_ = &stack_buf_[0];
|
used_buf_ = &stack_buf_[0];
|
||||||
} else {
|
} else {
|
||||||
heap_buf_ =
|
heap_buf_.reset(new char[block_size_ + kBlockTrailerSize]);
|
||||||
std::unique_ptr<char[]>(new char[block_size_ + kBlockTrailerSize]);
|
|
||||||
used_buf_ = heap_buf_.get();
|
used_buf_ = heap_buf_.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() {
|
void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() {
|
||||||
if (status_.ok() && read_options_.fill_cache &&
|
if (status_.ok() && read_options_.fill_cache &&
|
||||||
cache_options_.persistent_cache &&
|
cache_options_.persistent_cache &&
|
||||||
@ -143,6 +148,7 @@ void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() {
|
void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() {
|
||||||
if (status_.ok() && !got_from_prefetch_buffer_ && read_options_.fill_cache &&
|
if (status_.ok() && !got_from_prefetch_buffer_ && read_options_.fill_cache &&
|
||||||
cache_options_.persistent_cache &&
|
cache_options_.persistent_cache &&
|
||||||
@ -153,6 +159,7 @@ void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
void BlockFetcher::GetBlockContents() {
|
void BlockFetcher::GetBlockContents() {
|
||||||
if (slice_.data() != used_buf_) {
|
if (slice_.data() != used_buf_) {
|
||||||
// the slice content is not the buffer provided
|
// the slice content is not the buffer provided
|
||||||
@ -161,7 +168,7 @@ void BlockFetcher::GetBlockContents() {
|
|||||||
} else {
|
} else {
|
||||||
// page is uncompressed, the buffer either stack or heap provided
|
// page is uncompressed, the buffer either stack or heap provided
|
||||||
if (got_from_prefetch_buffer_ || used_buf_ == &stack_buf_[0]) {
|
if (got_from_prefetch_buffer_ || used_buf_ == &stack_buf_[0]) {
|
||||||
heap_buf_ = std::unique_ptr<char[]>(new char[block_size_]);
|
heap_buf_.reset(new char[block_size_]);
|
||||||
memcpy(heap_buf_.get(), used_buf_, block_size_);
|
memcpy(heap_buf_.get(), used_buf_, block_size_);
|
||||||
}
|
}
|
||||||
*contents_ = BlockContents(std::move(heap_buf_), block_size_, true,
|
*contents_ = BlockContents(std::move(heap_buf_), block_size_, true,
|
||||||
|
Loading…
Reference in New Issue
Block a user