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:
@@ -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?
|
// before we compact, can we merge with our siblings?
|
||||||
lfsr_rbyd_t sibling;
|
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++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
lfs_ssize_t sibling_rid;
|
lfs_ssize_t sibling_rid;
|
||||||
// try the right sibling
|
// try the right sibling
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
sibling_rid = rid+1;
|
sibling_rid = rid+1;
|
||||||
|
// no right sibling? can't merge
|
||||||
|
if (sibling_rid >= (lfs_ssize_t)parent.weight) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// try the left sibling
|
// try the left sibling
|
||||||
} else {
|
} else {
|
||||||
sibling_rid = rid-rbyd.weight;
|
sibling_rid = rid-rbyd.weight;
|
||||||
}
|
// no left sibling? can't merge
|
||||||
|
if (sibling_rid < 0) {
|
||||||
// no parent? no sibling?
|
|
||||||
if (rid == -1
|
|
||||||
|| sibling_rid < 0
|
|
||||||
|| sibling_rid >= (lfs_ssize_t)parent.weight) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// try looking up the sibling
|
// try looking up the sibling
|
||||||
// TODO do we really need to fetch sibling_weight if we get
|
// 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;
|
goto merge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// allocate a new rbyd
|
// allocate a new rbyd
|
||||||
err = lfsr_rbyd_alloc(lfs, &rbyd_);
|
err = lfsr_rbyd_alloc(lfs, &rbyd_);
|
||||||
|
|||||||
Reference in New Issue
Block a user