Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize retain() and retain_in() #939

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading