Skip to content

Qt paint: cache per-frame font_spec/layout_width in HistoryRowDelegate and view/viewport/wrap in QtNameWaveDelegate - #2339

Merged
trissim merged 1 commit into
mainfrom
perf/name-wave-delegate-state
Nov 27, 2026
Merged

trissim merged 1 commit into
mainfrom
perf/name-wave-delegate-state

Conversation

@trissim

@trissim trissim commented Nov 27, 2026

Copy link
Copy Markdown

Numbers first

  • 4-round alternating unprofiled A/B (HistoryRowDelegate.paint_row / paint_pictures, 6 visible rows x 1,000 frames):
    • BASE: [63.38, 67.52, 67.38, 68.50] -> median 67.45 ms
    • NEW: [51.13, 53.63, 51.92, 52.85] -> median 52.39 ms (1.29x speedup)
  • 4-round alternating unprofiled A/B (QtNameWaveDelegate.paint, 12 rows x 2,000 frames):
    • BASE: [139.06, 126.79, 130.28, 136.13] -> median 133.21 ms
    • NEW: [111.17, 117.41, 105.81, 107.73] -> median 109.45 ms (1.22x speedup)

What changed

  1. HistoryRowDelegate per-frame font_spec & layout_width caching (src/toad/qt/history.py:184, 601-676):
    • _resolve_frame_paint(painter, viewport_width) now resolves (font_family, font_size) and layout_width once in begin_paint instead of re-entering layout_width() (viewport().width()), preparation_key_for(), fragment_key(), drawn_key(), and _font_spec() (QFont::operator==) on every visible row of every scroll frame.
    • paint_pictures() looks up self._documents directly with the per-frame key (calling move_to_end on hit and falling back to final_document_for on miss).
  2. QtNameWaveDelegate.paint cached view/viewport + wrap fast path + idle/waving variant fix (src/toad/qt/name_wave.py:112-197):
    • Cached self._view = self.parent() and self._viewport = self._view.viewport() in __init__ and skipped redundant index.model() is not self._rows_model on _rows cache hits (eliminating two of the top Shiboken C++ boundary lookups per row paint).
    • Resolved wraps from row.wrap_mode.wrapped directly when set (falling back to view.wordWrap() only when row.wrap_mode is None) and reused it on cache misses instead of calling row.wraps(view) twice.
    • Included running in the _row_images variant key so idle (running=False, span=None) and bold waving between bands (running=True, span=None) cannot collide in the image cache.
  3. Focused regression tests (tests/model/test_android_perf_ux_arrivals.py, tests/textual/test_name_wave_repaint.py):
    • Verifies HistoryRowDelegate._font_spec runs once per frame across 5 painted rows.
    • Verifies QtNameWaveDelegate._row_images keeps (running=True, span=None) and (running=False, span=None) distinct.

Verification

  • pytest tests/model/test_android_perf_ux_arrivals.py tests/model/test_qt_history_width.py tests/textual/test_name_wave_repaint.py
  • tools/qt_inherit_ratchet.py, tools/shadow_check.py, tools/guarded_imports.py, REL_IMPORTS=0

…e and view/viewport/wrap in QtNameWaveDelegate
@trissim
trissim merged commit 472e6eb into main Nov 27, 2026
1 of 2 checks passed
@trissim
trissim deleted the perf/name-wave-delegate-state branch November 27, 2026 22:22
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