Skip to content

frame probe names every stall (Qt event or asyncio task); one-off actions reproduced at phone speed; tab switch and collapsed pane trimmed - #2106

Merged
trissim merged 2 commits into
mainfrom
fork-qt-stall-attribution
Nov 18, 2026
Merged

trissim merged 2 commits into
mainfrom
fork-qt-stall-attribution

Conversation

@trissim

@trissim trissim commented Nov 18, 2026

Copy link
Copy Markdown

The phone's probe log (#2102) showed one-off stalls of 1744, 901 and 339 ms, but not their causes. This PR makes the probe name every stall, reproduces the one-off actions cold at phone speed, and trims the per-open and per-switch work this PR owns.

1. The probe names each stall

The probe is still off by default. To turn it on: set TOAD_FRAME_PROBE=1, or create the file files/state/toad/frame-probe (on the phone, adb shell run-as org.toadcomms.toadcomms touch files/state/toad/frame-probe, then relaunch). It logs to files/state/toad/logs/frame-probe.log. The module docstring now gives the post-#2091 path.

A probed run writes one slow <ms> <what> line for every piece of work longer than 100 ms:

  • Qt events: a probed run's QApplication is a ProbedApplication, whose notify times each event's whole delivery. The line names the event type, the receiver's class and object name, and the nesting depth. All three QApplication creation sites go through FrameProbe.application: qt/main.py, qt/android.py and qt_drive.
  • asyncio callbacks: TimedHandles times every callback qasync runs from its Qt timers, and names a slow one's task and coroutine. Qt's run_operation now names each task after its OperationKind, so an operation reads as e.g. task=SessionRequestApply coroutine=TargetOpen.apply.
  • GC pauses: collections longer than 100 ms are logged too.

Cost: ProbedApplication.notify puts every Qt event through Python, which adds roughly 30% while many widgets are being built (Settings, a view's construction). The probed log is for attributing stalls; take timings from unprobed runs. All numbers below are unprobed.

2. One-off actions, cold, at phone speed

The new qt_drive.py actions scenario taps each action the way a finger does (QTest clicks on the row, the tab, the menu), each one cold and in its own probe window. Runs were at phone speed: one core at a 45% quota (the Pixel runs Python 2.15× slower than this desktop), offscreen, against the live bus. Worst stall per action on main f49a87a1, with the attributed cause from the probed run:

Action Worst stall Attributed to
Open Settings 1,027 ms QtSettingsScreen.__init__ → build_pages → FormFamily.pages (every page's editors at once). The startup fork owns this fix, so it is not changed here. On the phone, this is the most likely source of the 1,744 ms stall.
Open #comms, the first conversation of the run 585 ms TargetOpen.apply 554 ms (probed). About 365 ms of it is ConversationView → view_settings.configuration_state → ObjectConfiguration → objectstate: the first time a settings class is made lazy and its annotations are resolved (get_type_hints, annotationlib.__forward_code__). Then WorkingTranscript.execute at 190 ms.
Open #scratch, a second channel 414 ms TargetOpen.apply 329 ms (probed) and WorkingTranscript.execute 149 ms. The view's own ObjectState build costs about 125 ms per view, and the new page's first row layout about 260 ms (sizeHint plus _update_viewport, each row laid out as plain text and again as prepared HTML).
Open a thread 496 ms ThreadOpening.run 320 ms (probed): configuration_state 125 ms, the composer's construction 155 ms (one tick later), and the goal bar's first present_state 40 ms.
Switch tab 111 ms mark_current, plus TranscriptPresentation.published 131 ms (probed)
Toggle the thread pane 106 ms
Open the menu 58 ms
Expand a channel group 21 ms

3. Fixed here (both the per-open and the per-switch paths)

  • mark_current built every tab's label just to find the selected index. It ran session_navigation.tabs → connection.tab → history_entry.tab → project_value for every tab. SessionNavigator.tab_modes now reads the modes from the tab order, since a tab's mode is its identity's. mark_current runs on every open, every switch, and every paint_tabs, which is every bus change.
  • A collapsed thread pane bound every opened conversation. Binding listed the view's settings and bound its comms, plan and context panels, on every open and switch, for a pane showing only its bar. A collapsed pane now follows the welcome page, and opening it lays the panes out again, which binds the selected page. Following the welcome rather than the last page keeps no closed view behind the collapsed panels.

Times for the changed paths, from one run of actions per tree with the per-call timers on:

Path main branch
thread_pane.bind, median / max 5.1 / 60.2 ms 0.7 / 19.3 ms
thread_pane.setting_entries, calls 6 1 (only when the pane is opened)
mark_current, max 74.7 ms 28.3 ms
present_panes, median 15.9 ms 14.0 ms

The worst-stall-per-action table, run once per tree, is dominated by live-bus traffic landing in the same window. A single run moved by ±100 ms in both directions, which is more than these changes remove, so the per-call times above are the measure.

Not fixed here (other owners)

  1. Settings, 1,027 ms: owned by the startup fork.
  2. First conversation open, about 190 ms of first-time objectstate class setup: in objectstate (lazy_factory.make_lazy_simple, plus the type-hint resolution under ObjectState.__init__ and __init_with_tracking__). Fix it in objectstate, or prewarm it in CorePrewarm before the first frame (startup).
  3. Per-view ObjectState build, about 125 ms per opened conversation: objectstate _compute_resolved_snapshot → to_object → _reconstruct_from_parameter_snapshot.
  4. First row layout of a new page, about 260 ms: each row is laid out as a plain-text placeholder, then again when its HTML arrives from the pool, and each arrival relays out the view (RowDocumentDelegate._row_prepared → rows_changed, in pyqt-reactive and qt/history.py).

Checks on b3a73723 (main f49a87a1; the last commit only refactors the scenario timers)

  • Gates:
    • ratchet: copies 0, bare 21, both at baseline. ProbedApplication and TimedHandles are in QT_ONLY with reasons.
    • shadow_check: 0.
    • tools/android/check.sh: exit 0; the shipped app ran every view kind and bound key on a scratch bus.
  • qt_drive, once: placement 8/8, chrome 9/9, menu 12/12, tabs 5/5, history 7/7, with no tracebacks.
  • Not run: the TUI tests. The only shared change is SessionNavigator.tab_modes, a new property; nothing else on the TUI side changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

@trissim
trissim force-pushed the fork-qt-stall-attribution branch from b3a7372 to 8aefda5 Compare November 18, 2026 07:15
trissim and others added 2 commits November 18, 2026 02:21
…io task and coroutine, behind every piece of work over 100 ms

A probed run's QApplication times each event's whole delivery (ProbedApplication.notify) and
every asyncio callback (TimedHandles), and writes a `slow` line naming it; Qt's operation tasks
carry their OperationKind's name. Off unless asked for (TOAD_FRAME_PROBE, or the state folder's
frame-probe file; on the phone files/state/toad/frame-probe). qt_drive's `actions` scenario
taps the one-off actions cold, one probe window each.

Tab switches no longer project every tab's label to find the selected index (tab_modes reads
the modes from the tab order), and a collapsed thread pane follows the welcome instead of
binding each opened conversation's settings and panels.

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

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