Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(rendering): use binary search for cursor idle opacity move lookup

Richie McIlroy8932583f3a4c
diff --git a/crates/rendering/src/layers/cursor.rs b/crates/rendering/src/layers/cursor.rs
index c07cf0bd4..bfe7ad960 100644
--- a/crates/rendering/src/layers/cursor.rs
+++ b/crates/rendering/src/layers/cursor.rs
@@ -573,10 +573,13 @@ fn compute_cursor_idle_opacity(
return 1.0;
}
- let has_upcoming_move = cursor.moves.iter().any(|e| {
- e.time_ms > current_time_ms
- && e.time_ms - current_time_ms <= CURSOR_IDLE_RESUME_LOOKAHEAD_MS
- });
+ let idx = cursor
+ .moves
+ .partition_point(|e| e.time_ms <= current_time_ms);
+ let has_upcoming_move = cursor
+ .moves
+ .get(idx)
+ .is_some_and(|e| e.time_ms - current_time_ms <= CURSOR_IDLE_RESUME_LOOKAHEAD_MS);
if has_upcoming_move {
return 1.0;