Re: [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter
Onur Özkan <[email protected]> Tue, 28 Jul 2026 08:48:24 +0300
| Newsgroups | org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 27 Jul 2026 22:22:18 -0300 Rafael Passos <[email protected]> wrote: > Finding the next node in the RBTree can be done more efficiently using > the cursor_lower_bound, as it reduces cost from O(n) to O(log n). > > Link: https://github.com/Rust-for-Linux/linux/issues/1249 > Suggested-by: Alice Ryhl <[email protected]> > Signed-off-by: Rafael Passos <[email protected]> > --- > > (Sorry for the resend, my script missed the list) > > Hi, I decided to use the peek_next semantic instead of a loop/break. > Since the iterator should land directly on ptr or greater, I think this > is more elegant this way. But I can change it otherwise. > > Thanks, > Rafael > > > drivers/android/binder/process.rs | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs > index cdd1a90797266..c0c2112aca1c6 100644 > --- a/drivers/android/binder/process.rs > +++ b/drivers/android/binder/process.rs > @@ -1174,10 +1174,15 @@ fn get_node_debug_info(&self, data: UserSlice) -> Result { > > { > let inner = self.inner.lock(); > - for (node_ptr, node) in &inner.nodes { > + let cursor = inner.nodes.cursor_lower_bound(&ptr); > + if let Some(c) = cursor { Why not "if let Some(cursor) = inner.nodes.cursor_lower_bound..." ? > + let (node_ptr, node) = c.current(); > if *node_ptr > ptr { > node.populate_debug_info(&mut out, &inner); > - break; > + } else if *node_ptr == ptr { > + if let Some((_, next_node)) = c.peek_next() { > + next_node.populate_debug_info(&mut out, &inner); > + } > } > } > } > -- > 2.53.0 >