-
Notifications
You must be signed in to change notification settings - Fork 156
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)?) |
There was a problem hiding this comment.
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.
Thanks for the suggestion. I'm going to stick with this recursive
implementation for consistency with most of the rest of the code base, but
if you have any benchmarks on the overhead of the function calls, I'd be
very interested and open to changing if there's meaningful overhead
Sent from my phone
…On Mon, Sep 30, 2024, 12:25 AM Adam Reichold ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/tree_store/btree.rs
<#871 (comment)>:
> + &self,
+ page: PageImpl,
+ ) -> Result<Option<(AccessGuard<'static, K>, AccessGuard<'static, V>)>> {
+ let node_mem = page.memory();
+ match node_mem[0] {
+ LEAF => {
+ let accessor = LeafAccessor::new(page.memory(), K::fixed_width(), V::fixed_width());
+ let (key_range, value_range) = accessor.entry_ranges(0).unwrap();
+ let key_guard = AccessGuard::with_page(page.clone(), key_range);
+ let value_guard = AccessGuard::with_page(page, value_range);
+ Ok(Some((key_guard, value_guard)))
+ }
+ 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)?)
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.
—
Reply to this email directly, view it on GitHub
<#871 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGNXQG7WZSACU6NKGQD2FDZZD4GVAVCNFSM6AAAAABPCKJOAGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGMZWGYYTANBVGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change makes these methods almost 2x faster, by reducing the number of tree traversals from two to one.