Skip to content

Commit

Permalink
Optimize retain() and retain_in()
Browse files Browse the repository at this point in the history
Previously all freed pages went through the transactional free
mechanism. This commit changes it to reuse dirty pages
  • Loading branch information
cberner committed Jan 21, 2025
1 parent 89e55b7 commit fb125b4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tree_store/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ impl<K: Key + 'static, V: Value + 'static> BtreeMut<'_, K, V> {
{
let iter = self.range(&range)?;
let mut freed = vec![];
// Do not modify the existing tree, because we're iterating over it concurrently with the removals
// TODO: optimize this to iterate and remove at the same time
let mut operation: MutateHelper<'_, '_, K, V> =
MutateHelper::new_do_not_modify(&mut self.root, self.mem.clone(), &mut freed);
for entry in iter {
Expand All @@ -549,7 +551,12 @@ impl<K: Key + 'static, V: Value + 'static> BtreeMut<'_, K, V> {
assert!(operation.delete(&entry.key())?.is_some());
}
}
self.freed_pages.lock().unwrap().extend_from_slice(&freed);
let mut freed_pages = self.freed_pages.lock().unwrap();
for page in freed {
if !self.mem.free_if_uncommitted(page) {
freed_pages.push(page);
}
}

Ok(())
}
Expand Down

0 comments on commit fb125b4

Please sign in to comment.