Skip to content

Commit c3f6e4d

Browse files
generatedunixname1395027625275998meta-codesync[bot]
authored andcommitted
Cache GetKeysEndOffset in BlockIter to speed up Next inner loop (#14917)
Summary: Pull Request resolved: #14917 Reviewed By: kunalspathak Differential Revision: D110209012 fbshipit-source-id: 8ce3b94ea9617977d956f3856d92d50f2b547ddc
1 parent e1ea04d commit c3f6e4d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

table/block_based/block.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ class BlockIter : public InternalIteratorBase<TValue> {
465465
uint32_t restarts_; // Offset of restart array (list of fixed32)
466466
// current_ is offset in data_ of current entry. >= restarts_ if !Valid
467467
uint32_t current_;
468+
// Cached result of GetKeysEndOffset(). Computed once in InitializeBase()
469+
// since values_section_, data_, and restarts_ do not change afterward.
470+
uint32_t keys_end_offset_{0};
468471
// Raw key from block.
469472
IterKey raw_key_;
470473
// Buffer for key data when global seqno assignment is enabled.
@@ -588,6 +591,9 @@ class BlockIter : public InternalIteratorBase<TValue> {
588591
(block_restart_interval > 0 || num_restarts == 1)));
589592

590593
values_section_ = values_section;
594+
keys_end_offset_ = values_section_
595+
? static_cast<uint32_t>(values_section_ - data_)
596+
: restarts_;
591597
current_ = GetKeysEndOffset();
592598
}
593599

@@ -704,10 +710,7 @@ class BlockIter : public InternalIteratorBase<TValue> {
704710
// Return the offset where the keys section ends.
705711
// For separated KV storage, this is the start of the values section.
706712
// Otherwise, it's the start of the restart array.
707-
inline uint32_t GetKeysEndOffset() const {
708-
return values_section_ ? static_cast<uint32_t>(values_section_ - data_)
709-
: restarts_;
710-
}
713+
inline uint32_t GetKeysEndOffset() const { return keys_end_offset_; }
711714

712715
uint32_t GetRestartPoint(uint32_t index) const {
713716
assert(index < num_restarts_);

0 commit comments

Comments
 (0)