Re: [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter
Alice Ryhl <[email protected]> Tue, 28 Jul 2026 06:07:03 +0000
| Newsgroups | org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Jul 27, 2026 at 10:22:18PM -0300, Rafael Passos 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 { > + 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 > This would be a lot simpler if you just did `cursor_lower_bound(ptr+1)` so that you go straight to the right target node, instead of doing this if/else logic. Alice