Skip to content

Commit 92aafb1

Browse files
committed
fix: restore slot_db tier logic and fix performance regression
1 parent 3e00f14 commit 92aafb1

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

utils/slot_db/src/lib.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ where
104104
if self.data.entry(&slot).or_insert(DataCtner::new()).insert(k) {
105105
self.tiers.iter_mut().for_each(|t| {
106106
let slot_floor = slot / t.floor_base * t.floor_base;
107-
*t.data.entry(&slot_floor).or_insert(0) += 1;
107+
let mut v = t.data.entry(&slot_floor).or_insert(0);
108+
if 0 == *v {
109+
*t.entry_count.get_mut() += 1;
110+
}
111+
*v += 1;
108112
});
109113
*self.total.get_mut() += 1;
110114
}
@@ -149,6 +153,7 @@ where
149153
if 1 == *cnt {
150154
drop(cnt); // release the mut reference
151155
t.data.remove(&slot_floor);
156+
*t.entry_count.get_mut() -= 1;
152157
} else {
153158
*cnt -= 1;
154159
}
@@ -479,8 +484,12 @@ where
479484
Tier::new(self.tiers.len() as u32, self.tier_capacity),
480485
|mut t, (slot, cnt)| {
481486
let slot_floor = slot / t.floor_base * t.floor_base;
482-
*t.data.entry(&slot_floor).or_insert(0) += cnt;
483-
*t.entry_count.get_mut() += 1;
487+
let mut v = t.data.entry(&slot_floor).or_insert(0);
488+
if 0 == *v {
489+
*t.entry_count.get_mut() += 1;
490+
}
491+
*v += cnt;
492+
drop(v);
484493
t
485494
},
486495
);
@@ -491,9 +500,12 @@ where
491500
Tier::new(self.tiers.len() as u32, self.tier_capacity),
492501
|mut t, (slot, entries)| {
493502
let slot_floor = slot / t.floor_base * t.floor_base;
494-
*t.data.entry(&slot_floor).or_insert(0) +=
495-
entries.len() as EntryCnt;
496-
*t.entry_count.get_mut() += 1;
503+
let mut v = t.data.entry(&slot_floor).or_insert(0);
504+
if 0 == *v {
505+
*t.entry_count.get_mut() += 1;
506+
}
507+
*v += entries.len() as EntryCnt;
508+
drop(v);
497509
t
498510
},
499511
);
@@ -561,10 +573,7 @@ where
561573
K: Clone + Ord + KeyEnDeOrdered + Serialize + de::DeserializeOwned,
562574
{
563575
Small(BTreeSet<K>),
564-
Large {
565-
map: MapxOrd<K, ()>,
566-
len: usize,
567-
},
576+
Large { map: MapxOrd<K, ()>, len: usize },
568577
}
569578

570579
impl<K> DataCtner<K>

0 commit comments

Comments
 (0)