Skip to content

Commit b425372

Browse files
Korijnclaude
andauthored
Bisect the scheduler queue in place instead of slicing it (#191)
Splicing a watcher into a flushing queue sliced the tail of _queue_indices just to bisect it, copying O(n) entries on every mid-flush enqueue and then correcting the returned index by hand. Passing the lo bound to bisect searches the same range in place. Claude-Session: https://claude.ai/code/session_01UyALuqgF1ZZ3Lj88FzwGVc Co-authored-by: Claude <noreply@anthropic.com>
1 parent f113501 commit b425372

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

observ/scheduler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ def queue(self, watcher: Watcher[Any]) -> None:
206206
# If already past its id, it will be run next immediately.
207207
# Last part of the queue should stay ordered, in order to
208208
# properly make use of bisect and avoid deadlocks
209-
i = bisect(self._queue_indices[self.index + 1 :], watcher.id)
210-
i += self.index + 1
209+
i = bisect(self._queue_indices, watcher.id, self.index + 1)
211210
self._queue.insert(i, watcher)
212211
self._queue_indices.insert(i, watcher.id)
213212

0 commit comments

Comments
 (0)