Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter
@ 2026-07-28  1:22 Rafael Passos
  2026-07-28  5:48 ` Onur Özkan
  2026-07-28  6:07 ` Alice Ryhl
  0 siblings, 2 replies; 3+ messages in thread
From: Rafael Passos @ 2026-07-28  1:22 UTC (permalink / raw)
  To: rust-for-linux, gregkh, arve, tkjos, Christian Brauner, cmllamas,
	aliceryhl
  Cc: Rafael Passos

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 <aliceryhl@google.com>
Signed-off-by: Rafael Passos <rafael@rcpassos.me>
---

(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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter
  2026-07-28  1:22 [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter Rafael Passos
@ 2026-07-28  5:48 ` Onur Özkan
  2026-07-28  6:07 ` Alice Ryhl
  1 sibling, 0 replies; 3+ messages in thread
From: Onur Özkan @ 2026-07-28  5:48 UTC (permalink / raw)
  To: Rafael Passos
  Cc: rust-for-linux, gregkh, arve, tkjos, Christian Brauner, cmllamas,
	aliceryhl

On Mon, 27 Jul 2026 22:22:18 -0300
Rafael Passos <rafael@rcpassos.me> 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 <aliceryhl@google.com>
> Signed-off-by: Rafael Passos <rafael@rcpassos.me>
> ---
> 
> (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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter
  2026-07-28  1:22 [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter Rafael Passos
  2026-07-28  5:48 ` Onur Özkan
@ 2026-07-28  6:07 ` Alice Ryhl
  1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2026-07-28  6:07 UTC (permalink / raw)
  To: Rafael Passos
  Cc: rust-for-linux, gregkh, arve, tkjos, Christian Brauner, cmllamas

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 <aliceryhl@google.com>
> Signed-off-by: Rafael Passos <rafael@rcpassos.me>
> ---
> 
> (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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-28  6:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28  1:22 [PATCH] rust_binder: speed up get_node_debug_info using lower_bound iter Rafael Passos
2026-07-28  5:48 ` Onur Özkan
2026-07-28  6:07 ` Alice Ryhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox