Skip to content

paint: eliminate redundant per-frame work in MultilinePreviewItemDelegate and FittedText - #77

Merged
trissim merged 1 commit into
mainfrom
toad-qt/fast-preview-paint
Nov 24, 2026
Merged

trissim merged 1 commit into
mainfrom
toad-qt/fast-preview-paint

Conversation

@trissim

@trissim trissim commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Cuts redundant per-frame Python and Qt calls profiled in Toad's FrameWorkScenario:

  • MultilinePreviewItemDelegate.paint / _prepared_text: reuse view, row, wraps across paint without duplicate prepared_row() / wordWrap() / parent() calls; skip QRect.adjusted(0,0,0,0) when border_inset == 0.
  • MultilinePreviewItemDelegate.eventFilter: read event.type() once and use class-level frozenset DISCLOSURE_EVENTS instead of rebuilding a 4-item set literal on every event.
  • PreparedTextLayout.paint: skip list(...) copies and empty [] allocations when no inks apply.
  • FittedText / ElidedLine / WrappedText: cache alignment flags, WindowText palette color, and width-keyed elided string (invalidated on text/font/palette/style/enabled/alignment changes), cutting steady-state ElidedLine.paintEvent from 8 Python calls (with enum construction + re-elision) to 2.

Tests: test_list_preview_wrapping.py (27/27), test_fitted_text.py (2/2), test_virtual_rows_band.py (3/3) all pass.

…gate and FittedText

- MultilinePreviewItemDelegate.paint: bind parent view once instead of 6x, skip QRect.adjusted(0,0,0,0) when border_inset is 0, and pass the resolved (option, selected, row, wraps) tuple to _prepared_text so it does not re-call prepared_row() or view.wordWrap() on every painted row.
- MultilinePreviewItemDelegate.eventFilter: read event.type() once and match against class frozenset DISCLOSURE_EVENTS instead of reading event.type() twice and rebuilding a set literal on every Qt event.
- PreparedTextLayout.paint: call 2-arg QTextLayout.draw when no inks apply and avoid copying non-empty ink sequences per paint.
- FittedText / ElidedLine / WrappedText: cache alignment int flags, WindowText palette color (invalidated on Palette/Style/Enabled/ApplicationPaletteChange), and width-keyed elided text (invalidated on setText and Font/Style/ApplicationFontChange), cutting repeated ElidedLine.paintEvent calls from 8 Python calls (with enum churn and re-elision) to 2.
@trissim
trissim merged commit 5a0e2f7 into main Nov 24, 2026
@trissim
trissim deleted the toad-qt/fast-preview-paint branch November 24, 2026 00:52
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