Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

161 paired block bloom bpk adjustment #163

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions plugin/speedb/paired_filter/speedb_paired_bloom_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ inline int GetBitPosInBlockForHash(uint32_t hash, uint32_t set_idx) {

if (set_idx == 0) {
bitpos = hash >> 23;
if (LIKELY(bitpos > 6)) {
if (LIKELY(bitpos > static_cast<int>(kInBatchIdxNumBits - 1))) {
return bitpos;
}
hash <<= 9;
} else {
constexpr uint32_t mask = 0x007FC000;
bitpos = (hash & mask) >> 14;
if (LIKELY(bitpos > 6)) {
if (LIKELY(bitpos > static_cast<int>(kInBatchIdxNumBits - 1))) {
return bitpos;
}
}
Expand All @@ -214,7 +214,8 @@ inline void BuildBlock::SetBlockBloomBits(uint32_t hash, uint32_t set_idx,
size_t hash_set_size) {
for (auto i = 0U; i < hash_set_size; ++i) {
int bitpos = GetBitPosInBlockForHash(hash, set_idx);
block_address_[bitpos >> 3] |= (char{1} << (bitpos & kInBatchIdxNumBits));
// Find the byte, and set the proper bit within that byte
block_address_[bitpos >> 3] |= (char{1} << (bitpos & 7));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment here on why 3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expectation is that the code will work for any value that is <=8.
There is a comment there.
There are comments describing it (lines 41-42 of the source file) and static assertions to verify that the limit is 256 (the index must fit within a single byte, otherwise the code will break).
That is the reason for the >>3 and & 7
Per your request, I have added a comment to clarify the >> and & where they are used
Please see additional commit.

hash *= 0x9e3779b9;
}
}
Expand Down Expand Up @@ -268,7 +269,7 @@ bool ReadBlock::AreAllBlockBloomBitsSet(uint32_t hash, uint32_t set_idx,

#ifdef HAVE_AVX2
const __m256i mask_vec = _mm256_set1_epi32(0x007FC000);
const __m256i max_bitpos_vec = _mm256_set1_epi32(7);
const __m256i max_bitpos_vec = _mm256_set1_epi32(kInBatchIdxNumBits);
const __m256i fast_range_vec = _mm256_set1_epi32(KNumBitsInBlockBloom);
const __m256i num_idx_bits_vec = _mm256_set1_epi32(kInBatchIdxNumBits);

Expand Down Expand Up @@ -364,8 +365,8 @@ bool ReadBlock::AreAllBlockBloomBitsSetNonAvx2(uint32_t hash, uint32_t set_idx,
size_t hash_set_size) const {
for (auto i = 0U; i < hash_set_size; ++i) {
int bitpos = GetBitPosInBlockForHash(hash, set_idx);
if ((block_address_[bitpos >> 3] &
(char{1} << (bitpos & kInBatchIdxNumBits))) == 0) {
// Find the byte, and check the proper bit within that byte
if ((block_address_[bitpos >> 3] & (char{1} << (bitpos & 7))) == 0) {
return false;
}
hash *= 0x9e3779b9;
Expand Down
2 changes: 1 addition & 1 deletion plugin/speedb/paired_filter/speedb_paired_bloom_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace ROCKSDB_NAMESPACE {

namespace speedb_filter {
inline constexpr size_t kPairedBloomBatchSizeInBlocks = 128U;
inline constexpr size_t kPairedBloomBatchSizeInBlocks = 32U;
// Max supported BPK. Filters using higher BPK-s will use the max
inline constexpr int kMinMillibitsPerKey = 1000.0;

Expand Down