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 first() and last() #871

Merged
merged 1 commit into from
Oct 1, 2024
Merged

Optimize first() and last() #871

merged 1 commit into from
Oct 1, 2024

Conversation

cberner
Copy link
Owner

@cberner cberner commented Sep 30, 2024

This change makes these methods almost 2x faster, by reducing the number of tree traversals from two to one.

This change makes these methods almost 2x faster, by reducing the number of tree
traversals from two to one.
BRANCH => {
let accessor = BranchAccessor::new(&page, K::fixed_width());
let child_page = accessor.child_page(0).unwrap();
self.first_helper(self.mem.get_page_extended(child_page, self.hint)?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand tree depth is somewhat limited, but this looks highly amenable to an iterative implementation by basically putting all of this in a loop and writing

page = self.mem.get_page_extended(child_page, self.hint)?;

here with a

return Ok(Some((key_guard, value_guard)));

above to avoid the any questions of call overhead and/or stack usage.

@cberner
Copy link
Owner Author

cberner commented Oct 1, 2024 via email

@cberner cberner merged commit c620e53 into master Oct 1, 2024
3 checks passed
@cberner cberner deleted the first_last branch October 1, 2024 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants