mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
chore: performance improvements around zset (#1928)
1. ExpireIfNeeded was unjuistifiedly high in the profile topk table. Lets make the initial condition within an inline to reduce its impact. 2. Reserve space for hmap/zset if multiple items are added. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
9a09b793b4
commit
00ee506cc8
7 changed files with 76 additions and 14 deletions
|
@ -229,11 +229,13 @@ auto DenseSet::FindEmptyAround(uint32_t bid) -> ChainVectorIterator {
|
|||
}
|
||||
|
||||
void DenseSet::Reserve(size_t sz) {
|
||||
sz = std::min<size_t>(sz, kMinSize);
|
||||
sz = std::max<size_t>(sz, kMinSize);
|
||||
|
||||
sz = absl::bit_ceil(sz);
|
||||
capacity_log_ = absl::bit_width(sz);
|
||||
entries_.reserve(sz);
|
||||
if (sz > entries_.size()) {
|
||||
entries_.resize(sz);
|
||||
capacity_log_ = absl::bit_width(sz) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void DenseSet::Grow() {
|
||||
|
@ -622,20 +624,21 @@ auto DenseSet::NewLink(void* data, DensePtr next) -> DenseLinkKey* {
|
|||
return lk;
|
||||
}
|
||||
|
||||
bool DenseSet::ExpireIfNeeded(DensePtr* prev, DensePtr* node) const {
|
||||
bool DenseSet::ExpireIfNeededInternal(DensePtr* prev, DensePtr* node) const {
|
||||
DCHECK(node != nullptr);
|
||||
DCHECK(node->HasTtl());
|
||||
|
||||
bool deleted = false;
|
||||
while (node->HasTtl()) {
|
||||
do {
|
||||
uint32_t obj_time = ObjExpireTime(node->GetObject());
|
||||
if (obj_time > time_now_) {
|
||||
break;
|
||||
}
|
||||
|
||||
// updates the node to next item if relevant.
|
||||
// updates the *node to next item if relevant or resets it to empty.
|
||||
const_cast<DenseSet*>(this)->Delete(prev, node);
|
||||
deleted = true;
|
||||
}
|
||||
} while (node->HasTtl());
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue