Skip to content

virtual rows: a row is laid out once, in its final form; preparations arrive in batches - #63

Open
trissim wants to merge 2 commits into
mainfrom
rows-final-layout-batched
Open

trissim wants to merge 2 commits into
mainfrom
rows-final-layout-batched

Conversation

@trissim

@trissim trissim commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Summary

A virtual row is now laid out once, in its final form, and finished preparations reach the GUI thread in batches. Each batch costs one relayout of the view.

Before. While a row's formatting was being prepared on the pool, the row was laid out as plain text: a QTextDocument was filled, sized and cached. When the formatting arrived, that document and its height were dropped and the row was laid out again. Each arrival also started its own relayout.

After:

  • PendingRow. A row still being prepared stands in at a height estimated from its text's lines, with no document laid out. It paints that text with drawText. Nothing is cached for it, so the arrival lays it out once. RowFormatting.final says whether a formatting is the row's real one. RowFormatting.resolved() lets a formatting that prepares on demand resolve before it is measured.
  • Batched preparations. One RowPreparations runnable drains a PreparationQueue. It hands finished rows over when the queue empties, and at most every BATCH_SECONDS (0.1 s) while it is still working. _rows_prepared stores a batch, and the existing 16 ms timer lays the view out once for it.
  • final_document is the cached laid-out document, or None while the row is pending. paint and sizeHint use it. row_document still answers a pending row (a tap over it) with a plain document it doesn't keep.
  • LogItemDelegate.painted_document passes a pending row's None through to the new paint.

Measured in Toad's Qt client

Phone speed (45% of one core, Pixel 8a profile), unprobed qt_drive actions, 3 runs per tree, median. The action is opening a second channel (#scratch), cold:

before after
preparation arrivals (batches) 103 9
view relayouts 13 6
relayout time 542 ms 424 ms
sizeHint time 634 ms 491 ms
plain documents laid out and discarded 256 0

The remaining relayout time is the final layout of the page's rows: QListView asks every model row for its sizeHint. The page's worst single stall didn't move within the noise (450 → 470 ms median).

Tests

  • tests/test_virtual_rows.py and tests/test_log_viewer_lifecycle.py: 16 passed (main: 15).
  • New tests:
    • A pending row keeps no document or height.
    • A final row's height is kept once per width.
    • Forty rows queued together arrive in fewer than forty batches.
  • I couldn't run the full suite here, on main or on this branch: test_window_snapshot_bindings.py needs vispy, and the remaining suite segfaults offscreen on both trees.

The matching Toad change, PreparedOnFill.resolved, needs this merged first.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

… arrive in batches

A row's formatting is prepared on the delegate's pool. Until now the row was laid
out meanwhile as its plain text (a QTextDocument filled, sized and cached), and
when the formatting arrived that document and height were dropped and the row
laid out again; each arrival also started its own relayout of the view. Opening
a page of history in Toad's Qt client laid out 256 plain documents it threw
away, and took 103 arrivals and 13 relayouts.

- A row still being prepared is a PendingRow: it stands in at a height estimated
  from its text's lines (no document) and paints that text with drawText. Nothing
  is cached for it, so its prepared formatting is laid out once when it arrives.
  RowFormatting.final says which a formatting is; resolved() lets a formatting
  that prepares on demand resolve before it is measured.
- One RowPreparations runnable drains a PreparationQueue and hands finished rows
  to the GUI thread in batches: when the queue empties, and at most every
  BATCH_SECONDS while it works. _rows_prepared stores a batch, and the view lays
  out once for it on the next frame.
- final_document is the cached laid-out document (None while pending); paint and
  sizeHint use it. row_document still answers a pending row (a tap over it) with
  a plain document it does not keep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
…hat its key cached

Toad's history delegate (since toad#2110) overrides _row_prepared(key, prepared)
and calls it from adopt(), and while a row's new look is prepared it draws the
look the row last showed, a final formatting cached under the new key. So:

- _row_prepared(key, prepared) is the per-row arrival hook again. It stores the
  formatting, drops the documents and heights cached under the key, and starts
  the coalescing timer, so the view lays out once per frame however many land.
  _rows_prepared hands each row of a batch to it.
- _cached_widths indexes the widths each key has a document or height at, so
  the drop takes only that key's entries, not a scan of every cache.

A pending row still caches nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

This branch has not been deployed

No deployments
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