Added rbyd < 1/4 block_size condition to btree merges

This just avoids the overhead of estimating our sibling's sizes, which
we don't really want to do every compact.
This commit is contained in:
Christopher Haster
2023-08-20 01:18:05 -05:00
parent bacd09a673
commit 105a0a12ce
+11 -6
View File
@@ -3946,23 +3946,27 @@ static int lfsr_btree_commit(lfs_t *lfs, lfsr_btree_t *btree,
// before we compact, can we merge with our siblings?
lfsr_rbyd_t sibling;
if ((lfs_size_t)estimate <= lfs->cfg->block_size/4
// no parent? can't merge
&& rid != -1) {
for (uint8_t i = 0; i < 2; i++) {
lfs_ssize_t sibling_rid;
// try the right sibling
if (i == 0) {
sibling_rid = rid+1;
// no right sibling? can't merge
if (sibling_rid >= (lfs_ssize_t)parent.weight) {
continue;
}
// try the left sibling
} else {
sibling_rid = rid-rbyd.weight;
}
// no parent? no sibling?
if (rid == -1
|| sibling_rid < 0
|| sibling_rid >= (lfs_ssize_t)parent.weight) {
// no left sibling? can't merge
if (sibling_rid < 0) {
continue;
}
}
// try looking up the sibling
// TODO do we really need to fetch sibling_weight if we get
@@ -4023,6 +4027,7 @@ static int lfsr_btree_commit(lfs_t *lfs, lfsr_btree_t *btree,
goto merge;
}
}
}
// allocate a new rbyd
err = lfsr_rbyd_alloc(lfs, &rbyd_);