Skip to content

paint/layout: cache WrappedText.heightForWidth & sizeHint, skip no-op FittedText.setText - #78

Merged
trissim merged 1 commit into
mainfrom
fix/wrapped-text-cache
Nov 27, 2026
Merged

trissim merged 1 commit into
mainfrom
fix/wrapped-text-cache

Conversation

@trissim

@trissim trissim commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Eliminate redundant QFontMetrics.boundingRect and updateGeometry() layout churn seen in Toad's live #comms scroll profile (WrappedText.heightForWidth: 80 calls / 40 ms):

  1. Shared metrics cache invalidation on FittedText (src/pyqt_reactive/widgets/fitted_text.py):
    • Hoisted REMEASURES_ON (FontChange, StyleChange, ApplicationFontChange, ContentsRectChange) and _clear_metrics_cache() onto FittedText, removing duplicate setText/changeEvent overrides from ElidedLine and sharing the invalidation hook with WrappedText.
    • FittedText.setText(text) now returns early when text == self.text(), avoiding redundant setToolTip + updateGeometry() layout invalidations on periodic status/activity refreshes.
    • FittedText.minimumSizeHint() caches _min_size_hint.
  2. Cached WrappedText.heightForWidth(width) and sizeHint():
    • WrappedText caches _height_for_width = (width, height) and _size_hint, returning in O(1) when width, text, font, style, and contents margins are unchanged.

Verification

  • Focused pytest (tests/test_fitted_text.py, tests/test_status_line.py): 9 passed in 0.88s (including cache-hit, no-op setText, margin-change, font-change, and text-change invalidation assertions).
  • REL_IMPORTS=0.

@trissim
trissim merged commit 2bb0ba6 into main Nov 27, 2026
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