Skip to content

Perf: bulk sidebar reorder, skip unchanged/collapsed fit, wave-free sizeHint, cached floating_covers - #2343

Merged
trissim merged 1 commit into
mainfrom
perf/sidebar-bulk-reorder-fit-and-floating-covers
Nov 28, 2026
Merged

trissim merged 1 commit into
mainfrom
perf/sidebar-bulk-reorder-fit-and-floating-covers

Conversation

@trissim

@trissim trissim commented Nov 28, 2026

Copy link
Copy Markdown

Summary

Eliminates the remaining 258 ms MetaCall/_UiThreadCallProxy GUI stall on #comms open / sidebar sync and drops VirtualRowCanvas.scrollContentsBy + QtHistoryWindow.floating_covers completely off the FrameProbe top-samples radar:

  1. Bulk reorder in TreeItemRows._order_rows_immediate() (src/toad/qt/window.py:723-748)

    • On initial sidebar load, order_rows moved 74 out-of-place ThreadLine children one-by-one via takeChild + insertChild (148 rowsRemoved/rowsInserted signals). Each signal cleared MultilinePreviewItemDelegate._rows and forced QTreeView to re-run sizeHint -> StyledTextRenderer.prepare across every visible row (4,673 calls for 89 visible rows!).
    • When more than one child moves and none carries a Qt itemWidget, replaces the children in one bulk takeChildren() + addChildren(ordered) pair (2 signals instead of 2N), preserving expanded/selected state.
  2. Skip no-op SidebarItem.fit() writes and collapsed subtrees on resize (src/toad/qt/window.py:200,237-241,270-276,829,966-978)

    • Tracks SidebarItem._fitted_layout = (name, prefix, summary) so fit() skips setData(0, LAYOUT_ROLE, ...) (and its dataChanged -> forget_range invalidation) when elided text is unchanged (96% of rows on resize).
    • Walks visible_subtree() instead of subtree() in ConversationRows.resizeEvent and connects itemExpanded to _fit_expanded_children so collapsed channels cost 0 work on resize and refit lazily on expand.
  3. Skip bold/band layout cloning in QtNameWaveDelegate.sizeHint() (src/toad/qt/name_wave.py:214-223)

    • bold_titled and baked_band_layout preserve prepared.size identically; temporarily sets _active_wave = (False, None) during sizeHint so measurement never clones wave QTextLayouts.
  4. Cache QtHistoryWindow.floating_covers() (src/toad/qt/history.py:1345-1361,1518,1657-1709,2309-2326, src/toad/qt/virtual_scroll.py:1247-1251)

    • Caches (covers, opaque) across steady scroll frames and invalidates whenever sticky_header, jump_bar, or _viewport resizes, moves, or changes visibility, pairing with identity-hit lookup in VirtualRowCanvas.scrollContentsBy.

Measured Before vs After (#comms, 412x915, live bus)

  • Startup StyledTextRenderer.prepare() calls: 4,687 -> 561 (8.35x fewer, -88%)
  • Resize StyledTextRenderer.prepare() calls: 98 -> 4 (24.5x fewer, -96%; collapsed fits 165 -> 0)
  • Live FrameProbe #comms open / sidebar sync window:
    • slow MetaCall/_UiThreadCallProxy (>=100 ms): 258 ms -> 0 slow events (was 354 ms before #2342)
    • worst_stall_ms: 290.7 ms -> 63.0 ms (4.6x faster vs #2342, 6.2x faster vs pre-#2342 391.4 ms)
    • MetaCall/_UiThreadCallProxy total: 373 ms -> 108 ms (3.5x faster)
    • loop_busy: 12% -> 6% (was 15%)
  • Live FrameProbe 5 s #comms fling:
    • VirtualRowCanvas.scrollContentsBy (0.7%) + QtHistoryWindow.floating_covers (0.6%): both dropped completely off the top-14 sample list (<0.2%)
    • QtHistoryWindow.viewportEvent: 1.3% -> 0.9%

@trissim
trissim merged commit 7d0370b into main Nov 28, 2026
1 of 2 checks passed
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