Skip to content

Qt scroll: restore QtHistoryWindow.floating_covers, fast-path single opaque cover, cache RowPictures weight, guard QTimer teardown - #2338

Merged
trissim merged 1 commit into
mainfrom
perf/scroll-covers-and-pictures
Nov 27, 2026
Merged

trissim merged 1 commit into
mainfrom
perf/scroll-covers-and-pictures

Conversation

@trissim

@trissim trissim commented Nov 27, 2026

Copy link
Copy Markdown

Numbers first

  • 4-round alternating unprofiled A/B (VirtualRowCanvas.scrollContentsBy + QtHistoryWindow.floating_covers, 19 children, 2,000 scroll steps, PARITY=True):
    • BASE: [50.95, 74.41, 47.37, 75.82] -> median 62.68 ms
    • NEW: [46.38, 34.92, 29.03, 57.19] -> median 40.65 ms (1.54x speedup)
  • Clean 5 s live #comms 412x915 FrameProbe fling:
    • floating_covers: 2.4% -> 0.3% (8.0x reduction)
    • RowPictures.keep: 2.9% -> 0.7% (4.1x reduction)
    • Python work/frame: 269.1 -> 205.1 (-24%), viewportEvent 207+169 -> 147+140 (-29%), UpdateRequest/QtToadApp 938 ms -> 811 ms, paints 699 ms -> 585 ms, >=16 ms stalls 0

What changed

  1. QtHistoryWindow.floating_covers (src/toad/qt/history.py:1673):
    • #2336 renamed VirtualRowCanvas.scrollContentsBy's lookup from floating_over() to floating_covers(), bypassing QtHistoryWindow.floating_over() and regressing every scroll tick to self.children() across ~18 C++ child QObjects (2.4% of all CPU in live FrameProbe).
    • Replaced QtHistoryWindow.floating_over() with floating_covers(), inspecting only (self.sticky_header, self.jump_bar) and returning (covers, opaque).
  2. VirtualRowCanvas.floating_covers, uncovered, and scrollContentsBy (src/toad/qt/virtual_scroll.py:1202-1260):
    • Bound geo = child.geometry() and top_left = area.topLeft() once per visible child instead of repeated C++ calls.
    • Skipped sorted() allocation in uncovered() when len(covers) <= 1.
    • Added an exact area-invariant fast path in scrollContentsBy(): since clear and cover are disjoint subsets of vp_rect, area(clear) + area(opaque[0]) == area(vp_rect) holds iff vp_rect \ clear == opaque[0], skipping all 3 QRegion allocations/subtractions on steady-state sticky-header scroll ticks while still updating the opposite band for mid-viewport opaque covers.
  3. RowPictures cached tile weight + popitem(last=False) (src/toad/qt/history.py:766-780):
    • Cached tile byte weight in RowPictures.rows 4-tuple (look, document, picture, weight) and switched LRU eviction from self.drop(next(iter(self.rows))) (which also called picture.size() again on every eviction) to self.rows.popitem(last=False).
  4. QtToadApp._schedule_animation teardown guard (src/toad/qt/window.py:13, 2004):
    • Guarded self._animation_timer with shiboken6.isValid(...), fixing a real RuntimeError: Internal C++ object (QTimer) already deleted raised during app/widget teardown.
  5. Focused regression tests (tests/model/test_android_perf_ux_arrivals.py:2706-2740):
    • Mid-viewport opaque cover proves the area-invariant fast path does not false-positive.
    • QtHistoryWindow.floating_covers asserts self.children() is never called and splits opaque covers.
    • RowPictures verifies popitem(last=False) FIFO eviction and exact byte accounting.

Verification

  • pytest tests/model/test_android_perf_ux_arrivals.py: 42 passed in 0.75s
  • tools/qt_inherit_ratchet.py: 0/0/0/0/0
  • tools/shadow_check.py: 0
  • tools/guarded_imports.py: 0
  • REL_IMPORTS=0

…opaque cover, cache RowPictures weight, guard QTimer teardown
@trissim
trissim merged commit 11b53fc into main Nov 27, 2026
1 of 2 checks passed
@trissim
trissim deleted the perf/scroll-covers-and-pictures branch November 27, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant