Skip to content

sidebar drag: a held extent is drawn, not written; kept once on release; layout binds nothing - #2107

Merged
trissim merged 1 commit into
mainfrom
fork-sidebar-drag-speed
Nov 18, 2026
Merged

trissim merged 1 commit into
mainfrom
fork-sidebar-drag-speed

Conversation

@trissim

@trissim trissim commented Nov 18, 2026

Copy link
Copy Markdown

Tristan: "resizing the bar is very, very slow. It was slow in the TUI, and it's also slow on Android and in the GUI."

What a drag cost (profile, Qt offscreen, Pixel 8a width, #comms open, 40 handle moves)

cost per move where
settings write SidebarLayout.resize → _store → store_terminals → objectstate update_parameter and invalidation, 0.70 s over 19 writes (37 ms each, plus 0.54 s of dataclass validation under it)
toad.json save SidebarSurface.arranged → keep_settings
Core reads each Qt layout pass called _bind_thread_pane, re-presenting the Comms and Context panels, which started thread_comms_source.relationships (1.54 s) and context refreshes
re-measure every width change re-fitted every channel row (ConversationRows.resizeEvent → fit, ~1,100 calls) and re-laid out the pages

Fix, at the owners (both frontends through the shared rule)

  • SidebarLayout holds a grip's extent (hold / keep_held / drop_held). placements draws the held extent and resting_placements is what the settings keep. Nothing is written during a drag.
  • Shared drag rule (SidebarSurface.extent_dragged / extent_released):
  • SidebarChromeArrangement: while a hold is on, the conversation keeps the room the kept arrangement gives it, so its rows are measured once, on release, in Qt and the TUI alike.
  • Qt layout pass (rearrange_sidebars):
    • It presents and places the bars, coalesced to one pass per turn of the event loop, and binds nothing.
    • The thread pane follows the selected page (present_panes), not geometry.
    • A held bar's content keeps its length against the wall, so its rows are fitted once, on release.
  • TUI: CapturedDrag already folds queued moves into the newest one, so slow frames never build a backlog.

Before / after, at phone throttle (systemd-run --user --scope -p CPUQuota=45%), main and branch run back to back

The machine was loaded by other work (load average ~12), so compare within a row, not across runs.

Qt (qt_drive drag_speed, 40 moves, one 16 ms frame after each):

main branch
move handled, p95 / max 500.6 / 878.7 ms 0.3 / 50.3 ms
loop late after a move, median / p95 80.1 / 292.1 ms 50.5 / 84.6 ms
release 0.2 ms 696 ms

TUI (pilot drag of the resize handle, 40 moves, time to the drawn screen; two interleaved rounds):

main branch
round 1, median / p95 287.8 / 303.4 ms 28.2 / 86.0 ms
round 2, median / p95 222.9 / 296.9 ms 83.2 / 100.3 ms
  • Qt move handling: now 0.2 ms.
  • Qt loop lateness that remains: machine load plus live-bus traffic. In an unthrottled profile, the drag's own work is under 1 ms a move. What runs in the loop is remote_core.call and field_codec decoding of observations.
  • Release: it carries the one settings write (objectstate validation and invalidation, ~110 ms unthrottled) and one re-layout of the pages. That cost is now paid once per drag instead of on every move. Making objectstate's own write cheaper would be a separate change.
  • Targets: not met under this load. The Qt drag no longer does work per move, but loop lateness is p95 85 ms. The TUI is p95 86–100 ms per drawn move in the pilot harness, a measure that also includes Textual's own layout and paint pass.

Checks (final head 0894315 on main 75dc1de)

  • TUI sidebar tests (pointer focus, direction, notifications, drag resize, layout policy): main 2 failed / 108 passed, branch 2 failed / 108 passed. The same two fail on both.
  • qt_drive slide: exit 0, with the grip behaviour unchanged (fold at the wall keeps the extent, strip click reopens, strip drag opens, slider to 0 folds). This includes sidebar grips: drag to the wall folds, the strip reopens or drags open; panes and tabs animate #2100 if it lands first.
  • Gates: ratchet bare 21/21, copies 0, Textual-UI modules 11/11, toad.qt → widgets imports 0. shadow_check finds 0. tools/android/check.sh exits 0, including the shipped-app run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

@trissim
trissim force-pushed the fork-sidebar-drag-speed branch from 0894315 to f236fcc Compare November 18, 2026 07:32
@trissim

trissim commented Nov 18, 2026

Copy link
Copy Markdown
Author

Rebased onto c4e25bd (f236fcc). One change beyond the rebase, to agree with #2106: #2106's _bind_thread_pane relies on a layout pass binding the selected page when the folded thread pane opens, and this PR had made layout passes bind nothing. Now the coalesced layout pass calls present_panes again (so opening the pane binds the selected page, and folding it follows the welcome), and ThreadPane.bind returns early for the view it already follows. A resize binds the same view every frame, so it costs nothing. drag_speed at CPUQuota=45% (load average 14): move handled p95 0.2 ms, loop late median 0.9 / p95 78.7 ms, release 306 ms. Ratchet and shadow_check clean; tools/android/check.sh exits 0 including the shipped-app run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

…se; layout binds nothing

Profile of a drag (Qt offscreen, Pixel 8a width, #comms open): every grip move wrote the
arrangement into the settings (SidebarLayout.resize -> _store -> objectstate update and
invalidation, ~37 ms each) and saved toad.json (SidebarSurface.arranged -> keep_settings); every
Qt layout pass re-bound the thread pane, re-presenting its Comms and Context panels, which started
Core reads; and every width change re-fitted every channel row's text and re-measured the pages.

- SidebarLayout holds a grip's extent in memory (hold / keep_held / drop_held): `placements` draws
  it, `resting_placements` is what the settings keep. The shared drag rule (SidebarSurface
  extent_dragged / extent_released) only holds and lays out while held, and on release writes the
  held extent once and keeps the settings once (or, released at the wall, drops it and folds).
- SidebarChromeArrangement: while a hold is on, the conversation keeps the room the kept
  arrangement gives it, so it is laid out (its rows measured) once, on release, in both frontends.
- Qt: a layout pass (rearrange_sidebars) presents the bars and places them, coalesced to one per
  turn of the event loop, and binds nothing; the thread pane follows the selected page
  (present_panes), not geometry. A held bar's content keeps its length against the wall, so its
  rows are fitted once, on release.
- qt_drive `drag_speed`: 40 handle moves with #comms open; per-move handling time, the loop's
  lateness after each move, the release, and a profile (TOAD_DRAG_PROFILE=1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
@trissim
trissim force-pushed the fork-sidebar-drag-speed branch from f236fcc to 20fae08 Compare November 18, 2026 07:43
@trissim

trissim commented Nov 18, 2026

Copy link
Copy Markdown
Author

Rebased onto 3712ef8 (20fae08), with one fix.

ThreadPane.bind returned early for the view it already followed. But the Comms and Context panels have no bus subscription: they refreshed only because every observation update re-bound the same view (sidebar redraw → paint_tabs → mark_current → present_panes). A probe swapped in a new coordination revision with tab A still shown and called paint_tabs. It showed 0 refreshes, so the panels went stale.

bind now skips only when both the view and coordination_access.revision are the ones its panels show. It re-binds the panels on a revision change, and re-lists the settings entries only for a new view.

Probe after the fix:

  • Unchanged revision: 0 refreshes.
  • Changed revision: 1 Comms refresh and 1 Context refresh.
  • A → B → A binds each view (Comms 5 rows, Context 2).
  • The strip opens the pane onto the selected page, and folding follows the welcome.

Checks:

  • Drives slide, chrome, tabs and placement exit 0.
  • Ratchet and shadow_check are clean.
  • tools/android/check.sh exits 0, including the shipped-app run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

@trissim
trissim merged commit 11eb3b8 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