Skip to content

qt views: the composer is built just after the history first paints - #2124

Merged
trissim merged 1 commit into
mainfrom
fork-qt-second-channel
Nov 18, 2026
Merged

trissim merged 1 commit into
mainfrom
fork-qt-second-channel

Conversation

@trissim

@trissim trissim commented Nov 18, 2026

Copy link
Copy Markdown

Summary

This is the second-channel open, at the view owner. A Qt view now builds its composer just after its history first paints, instead of inside its constructor. It goes with PyQT-reactive#65, where a layout lays out only the rows near the reader.

Why the view, not only sizeHint. On the live bus, at phone speed (probed, py-spy), the second channel's worst stall was the target open itself: 491 ms, task=SessionRequestApply. 335 ms of that was ConversationView's constructor, and 170 ms of that was the composer (channel_prompt: ComposerEditor, place_input_box, focus_changed, paint_colours). Row measurement happened in the relayouts after it, as separate stalls.

QtConversation.reserve_composer, one owner for every view kind:

  • Placeholder. The composer's place in the layout holds a ComposerPlaceholder. It's as tall as that view kind's composer last asked to be (composer_heights, from its sizeHint), or an estimate from the composer's parts before the first one.
  • Mount. The composer is built just after the history viewport's first Paint (an event filter, then a zero timer), replacing the placeholder in place.
  • Ready before typing. A tap or focus on the placeholder builds the composer at once and gives it the focus.
  • Hidden views. A view that's never shown (a restored background tab) builds no composer until it is.
  • on_composer(kind, apply). What the composer is told before it exists (label, status, commands, hold, receipt, mention candidates) applies at the mount. Only the latest of each kind is kept, so nothing piles up while a view is hidden.
  • Close. close_core_events forgets a composer that hasn't been built yet.

ConversationView and QtThreadView (so mailbox and ACP) both reserve it this way.

  • The thread view's own one-tick QTimer mount and its copy of the "Composer mount failed" handling are gone.
  • The question under the composer keeps its place.
  • On Android the composer stays out of the first frame's EGL setup, as before.

Placeholder vs built height (Pixel 8a profile): 60 px / 60 px for the channel, DM and mailbox views, including the first composer of a run.

I didn't change composer internals or paint_colours. Lines the other forks will touch:

  • File-picker fork (fork-android-file-picker-2): Attach and chips in QtMessageComposer; the attach owner in toad.client.prompt_composer. This PR doesn't touch either. If it adds anything that tells the view's composer something before it exists, that goes through on_composer.
  • Contrast fork (fork-qt-theme-contrast): paint_colours. Untouched here. It runs inside the deferred build now, so it's no longer in the open's stall.

tools/qt_drive.py (tools only): FRAME_TIME_OPEN also times the composer's mount, the delegate's new_document / final_document, and the history's fragment_height / block_row. It prints each composer's placeholder height beside its built height.

Depends on

These arrive with the runtime rebuild: the runtime resolves each library at main, and the APK bundles the runtime's site-packages. This PR's Toad code runs on the installed libraries too: check.sh passes against the current runtime.

Measured (fixed bus, 1 core, unthrottled)

The phone-speed throttle (systemd-run --user … CPUQuota=45%) needs the host's user systemd manager, which is down since the OOM. The live bus is down with it. So these numbers are from a fixed local bus (150 synthetic messages each on #comms and #scratch, plus the thread scratch-live-pipeline), driven by qt_drive actions --comms-root, pinned to 1 core and unthrottled. They're a relative before/after, not phone speed. 3 valid runs per side, median. (Runs that timed out at "welcome rows" during startup under host load are left out and were rerun.)

These are two separate A/Bs, each against its own baseline, and they shouldn't be read across. The same configuration measured differently between the two sessions: the second A/B's "without band" #scratch was 44.8 ms, where the first A/B's "deferred composer" column has 20.1 ms.

1. This PR (#2112's head vs this branch, both with PyQT-reactive#63, without #65), worst stall:

#2112's head deferred composer
second channel (#scratch) 40.1 ms (82, 40, 34) 20.1 ms (40, 16, 20)
first channel (#comms) 48.7 ms (49, 53, 40) 37.0 ms (37, 49, 19)
thread 46.6 ms (44, 47, 50) 58.1 ms (63, 58, 33)

The composer mount is now its own step after the paint: 14–27 ms on this core.

2. PyQT-reactive#65 (this branch, with and without the band):

without band with band
#scratch: worst stall 44.8 ms 20.0 ms
#scratch: relayout / sizeHint 23 / 17 ms 8 / 7 ms
#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 thread's worst stall isn't settled by A/B 1. Its composer was already deferred by one tick before this change. Its runs overlap (33–63 ms against 44–50 ms), and in A/B 2 one thread run stalled 246 ms while its row and relayout timers totalled under 90 ms, so this fixture can't attribute it.

The phone-throttled 3-run medians against the target (second-channel worst stall under 300 ms), and the live-bus reruns, follow once the user manager and the live bus are back.

Gates (once, on this head, a3c1492 over 19058d2)

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

Opening a second channel at a phone's speed held the loop for one long stall, and 335 ms
of the 491 ms (probed) was ConversationView's constructor: 170 ms of it the composer
(channel_prompt: ComposerEditor, place_input_box, focus_changed, paint_colours). Rows
are measured in the relayouts after it.

QtConversation.reserve_composer is the one owner for every view kind:
- the composer's place in the layout holds a ComposerPlaceholder, as tall as that view
  kind's composer last asked to be (composer_heights, its sizeHint), else an estimate
  from its parts (the editor's line and padding over the info bar's line);
- the composer is built just after the history viewport's first Paint (an event filter,
  then a zero timer), replacing the placeholder in place;
- a tap or focus on the placeholder builds it at once and hands it the focus, so typing
  never waits; a view never shown (a restored background tab) builds none until it is;
- what the composer is told before it exists goes through on_composer: now once it is
  built, else at the mount, the latest of each kind (label, status, commands, hold,
  receipt, mention candidates), so nothing piles up while a view is hidden;
- close_core_events forgets a composer not built yet.

ConversationView and the thread views (QtThreadView, so mailbox and ACP) reserve it the
same way; the thread view's one-tick QTimer mount goes, and so does its own copy of the
"Composer mount failed" handling. The question under the composer keeps its place. On
Android the composer stays out of the first frame's EGL setup, as before.

Measured placeholder vs built height (Pixel 8a profile): 60 px / 60 px for the channel,
DM and mailbox views.

tools/qt_drive.py (tools only): FRAME_TIME_OPEN also times the composer's mount, the
delegate's new_document / final_document and the history's fragment_height / block_row,
and prints each composer's placeholder height beside its built one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
@trissim
trissim merged commit a2bcee5 into main Nov 18, 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