From fbe95d84f3f1be0ee4a88fa18831066f031b9ee7 Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Wed, 18 Nov 2026 10:07:13 -0500 Subject: [PATCH] name wave: a frame repaints a line only when its band moved to other cells The band is drawn in whole cells, so a frame that leaves it on the same cells paints the same line. On a busy bus (the laptop's: about 30 working threads in the sidebar) 40% of the ~600 sidebar row repaints a second were such frames, each building a new QTextLayout. `NameWave.wave_moved` decides it once for every frontend from the span a line drew last; a wave that starts or stops forgets it, so its first frame (the name turning bold) draws. Qt's sidebar rows ask it before invalidating their rect. Measured with `qt_drive idle` against the laptop's bus, untouched, median CPU: home 6.4-7.0% -> 5.0%, #comms 5.6-6.7% -> 4.8% (animations off: 1.1% / 0.9%). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3 --- src/toad/client/name_wave.py | 10 ++++++++++ src/toad/qt/window.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/toad/client/name_wave.py b/src/toad/client/name_wave.py index 1f92e73dd..229513bb2 100644 --- a/src/toad/client/name_wave.py +++ b/src/toad/client/name_wave.py @@ -33,6 +33,14 @@ class NameWave(BandCells): and paints the frame it reads.""" name_wave: ClassVar[Effect[Band]] = NAME_WAVE + painted_span: tuple[int, int] | None = None # the band's cells as the line last drew them + + def wave_moved(self, span: tuple[int, int] | None) -> bool: + """Whether a frame's band covers other cells than the line last drew. The band is + drawn in whole cells, so a frame that leaves it on the same cells would paint the same + line: on a busy bus about 40% of 660 sidebar row frames a second did (`qt_drive idle`).""" + moved, self.painted_span = span != self.painted_span, span + return moved def wave_running(self) -> bool: raise NotImplementedError @@ -47,8 +55,10 @@ def follow_activity(self, busy: bool) -> None: """Being busy is drawn, never spelled: it starts the wave without changing the text.""" if busy: if not self.wave_running(): + self.painted_span = None # its first frame draws: the name turns bold with it self.start_wave() else: + self.painted_span = None self.stop_wave() def name_bold(self) -> bool: diff --git a/src/toad/qt/window.py b/src/toad/qt/window.py index 34b09aaca..04c557555 100644 --- a/src/toad/qt/window.py +++ b/src/toad/qt/window.py @@ -380,7 +380,7 @@ def animation_visible(self) -> bool: def repaint(self) -> None: tree = self.treeWidget() - if tree is not None: + if tree is not None and self.wave_moved(self.wave_span()): tree.viewport().update(tree.visualItemRect(self)) def wave_span(self) -> tuple[int, int] | None: