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; 4+ 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] 4+ messages in thread
[parent not found: <20260728010717.3075755-1-rafael@rcpassos.me>]

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

Thread overview: 4+ 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
     [not found] <20260728010717.3075755-1-rafael@rcpassos.me>
     [not found] ` <2026072804-sedation-bogged-6f89@gregkh>
     [not found]   ` <CAH5fLgh6jyOOW=nHatA=wOc0fjwk7k5VUJgtk0HNz4zdUScN_g@mail.gmail.com>
2026-07-28 20:59     ` Rafael Passos

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