Skip to content

virtual rows: a layout lays out only the rows near the reader; the rest are measured between frames - #65

Open
trissim wants to merge 1 commit into
rows-final-layout-batchedfrom
rows-measured-near-reader
Open

trissim wants to merge 1 commit into
rows-final-layout-batchedfrom
rows-measured-near-reader

Conversation

@trissim

@trissim trissim commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Summary

A layout of a VirtualRowView now lays out only the rows near the reader. The rest are measured between frames, nearest the reader first, with the reader held in place.

QListView asks every model row for its size on every layout. So a page's first layout laid out every row's final document, the rows far above the reader as much as the ones on screen. In Toad's Qt client at phone speed on the live bus, that was 244–289 ms of sizeHint per second-channel open, and about 100 ms for the largest single relayout.

What changes:

  • VirtualRowView.doItemsLayout. Before Qt's layout pass, it measures the rows within MEASURED_VIEWPORTS (2) viewports' height above and below the reader's row. The reader's row (reader_row) is the newest one at the end, else the one at the viewport's top. The pass then runs with estimating() true.
  • While estimating, the delegate answers a row it has no size for with an estimate from its plain text's lines (estimated_size) and queues it.
  • _measure_slice lays the queued rows out between frames, nearest the reader first, 8 ms (MEASURE_SLICE_SECONDS) at a time. Then it lays the view out once through rows_changed.
  • rows_changed now keeps the end for a reader at it, and otherwise holds the row under the reader. So measuring rows above never moves what the reader sees. A subclass's own rows_changed (Toad's holds the reader itself) is used as is.
  • measured_size is the one place a row's height is laid out and kept. sizeHint and the slices both go through it.

This stacks on #63 (base rows-final-layout-batched).

Measured

In Toad's Qt client, on a fixed local bus (150 synthetic messages each on #comms and #scratch, plus a thread). 1 core, unthrottled (taskset -c 5): the phone-speed throttle needs the host's user systemd manager, which is down. Same Toad tree on both sides, 3 runs each, median.

without with
second channel (#scratch): worst stall 44.8 ms 20.0 ms
#scratch: relayout time / sizeHint time 23 / 17 ms 8 / 7 ms
first channel (#comms): worst stall 40.3 ms 24.4 ms
#comms: relayout / sizeHint 21 / 17 ms 9 / 10 ms
thread: worst stall 83.9 ms 61.2 ms
thread: relayout / sizeHint 29 / 46 ms 14 / 31 ms

The phone-throttled and live-bus numbers come once the host's user manager and the live bus are back.

Tests

  • New tests/test_virtual_rows_band.py:
    • A 400-row view at the end measures fewer than 100 rows in its first layout.
    • Every row is then measured between frames, and the reader stays at the end.
    • A reader scrolled to row 300 stays on the same top row while the rows above are measured.
  • test_virtual_rows.py, the band tests and test_log_viewer_lifecycle.py: 18 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

…st are measured between frames

QListView asks every model row for its size on every layout, so a page's first layout
laid out every row's final document, the rows far above the reader as much as the ones
on screen (on a second channel in Toad's Qt client at a phone's speed, 244-289 ms of
sizeHint per open, the largest relayouts about 100 ms each).

- VirtualRowView.doItemsLayout first measures the rows within MEASURED_VIEWPORTS (2)
  viewports' height above and below the reader's row (reader_row: the newest at the
  end, else the row at the viewport's top), then lays out with `estimating()` true.
- While estimating, the delegate answers a row it has no size for with an estimate
  from its plain text's lines (estimated_size, PendingRow's estimate) and queues it.
- _measure_slice lays the queued rows out between frames, nearest the reader first,
  for MEASURE_SLICE_SECONDS (8 ms) at a time, then lays the view out once with
  rows_changed, which now keeps the end for a reader at it and holds the row under the
  reader otherwise, so measuring rows above never moves what the reader sees.
- measured_size is the one place a row's height is laid out and kept; sizeHint and the
  slices go through it.

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