Skip to content

perf: resize a terminal's grid the moment its pane is drawn - #1283

Merged
yansfil merged 5 commits into
mainfrom
grid-ahead-of-herdr
Oct 16, 2026
Merged

yansfil merged 5 commits into
mainfrom
grid-ahead-of-herdr

Conversation

@yansfil

@yansfil yansfil commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: PRD grid-ahead-of-herdr (local), follows instant-pane-topology (#743)

Summary

In a tab with several panes, a zoom, divider drag, pane close or split moved the pane rectangles at once, but the text inside kept its old grid until Herdr confirmed the layout and the core sent the PTY size: the terminal looked like it stretched slowly.
The core held that size on purpose, on the belief that Herdr sizes the PTY from the geometry it applies. On the pinned Herdr 0.9.3 it does not: the PTY is the controlling client's size through a zoom, a split and a sibling's close, which a new contract test pins.
The hold is gone. The shell fits each terminal to the rectangle drawn for it the moment it is drawn, the node sends that size at once, and Herdr's later layout changes nothing when it matches. A timing record's frame watch now starts at that resize instead of at Herdr's confirmation.
Two measurement fixes ride along: the topology scenario presses the current zoom chord, and a new pane's cwd answer republishes only when it would change the screen (one full publish saved per split or new tab at operator scale).

Review

  • 판단해 주세요: hide-herdr-client/tests/it/real_herdr.rs is where the D-14 contract test lives (the os contract lane runs on all three systems); the PRD named hided/tests/it/real_herdr.rs, which runs on Windows only.
  • 조심해서 볼 파일: herdr-core/src/runtime/events.rs - TerminalResize no longer has a held branch; a resize now reaches the node whenever the core's recorded size differs (high-frequency path, under the runtime mutex).
  • 조심해서 볼 파일: herdr-core/src/runtime/op_timing.rs - a resize marks every record on that pane that is drawn or applied; two operations on one pane share one resize (timing only, no behaviour).
  • 조심해서 볼 파일: herdr-core/src/session_sync/coordinator.rs - pane_cwds_answer_publishes skips a publish; the skip is wrong if a pane the screen shows at a stand-in could stay there, which CatalogState::stand_ins guards (failure path: a pane left in the wrong folder).
  • 조심해서 볼 파일: hide-node-link/src/lib.rs - TerminalControl::Resize lost force; the enum does not deny unknown fields, so an older node reading a newer link and the reverse both parse.
  • 비용 검토: per resize, OpTimings::resize_sent scans at most 64 open records with no allocation, and one WatchFrame goes out only when a record starts waiting; stand_ins holds at most UNCONFIRMED_CWD_LIMIT (64) entries and is replaced per publish; nothing new runs per tick or per frame.

Evidence

  • 확인한 것: the pinned Herdr 0.9.3 keeps a controller's 45x20 PTY through a zoom on and off and a sibling pane's close, read by stty size after each step and by the frame size the controller receives (new contract test, passed locally with HIDE_E2E_HERDR_BIN; the code reviewer ran it 42 times, 6 sequential and 36 concurrent, all green).
  • 확인한 것: pane_geometry tests pin one PTY size per zoom at the drawing and none when Herdr confirms the same layout, a resize before the drawing starts no frame watch, and a refused operation sends nothing more.
  • 확인한 것: same fixture, same machine, before (the bundle installed at the time, 0.4.1-main.e8c08186 by its Info.plist and the sha256 of its hided, which now sits beside the app as hide-previous-0.4.1-main.e8c08186.app.bak; it is main five commits past the merge base 7f02ba5, and that range touches no terminal, node or shell path, only delivery.rs; the installed app has since moved to 0.4.1-main.fdc68c74, so a rerun against it is a different baseline) and after (release build of this branch), MEASURE_SCENARIO=topology --isolated-headless, operator scale (43 workspaces, 62 tabs, 66 panes, 30 agents, 5 printing), 10 rounds each, page clock from the key press to the first frame with the new grid:
op before p50 / p95 ms (load 36-58) after p50 / p95 ms (load 25-44)
zoom 94.1 / 110.2 24.1 / 42.1
unzoom 27.4 / 412.3 27.9 / 33.5
close 126.6 / 160.5 27.6 / 44.0
split 97.4 / 1015.2 129.0 / 309.9
new_tab 132.2 / 581.6 137.3 / 960.2

After the change the first frame with the new grid arrives in the same frame as the rectangle (frame = screen for zoom, unzoom and close); split and new_tab wait for a pane that does not exist yet, so their path is unchanged and the difference is load noise.

  • 확인한 것: pane_op.timing in the after run, operator scale: zoom first_frame p50 22 ms with the resize at the drawing (drawn p50 8 ms), and one terminal.resize_settled per operation (40 for 40), none on Herdr's confirmation; pane.prediction_mismatch 0.
  • 확인한 것: the measured release binary was built from the tree between 310ef51 and 2bdedef; the two commits after it change only timing-record gating, comments, tests and the cwd-answer guard, none on the terminal path.
  • 확인한 것: the contract test passed in the os contract lane on macOS, Linux and Windows (verify run 38922022691); the Windows branch asserts the frame size after each step but not stty.
  • 확인하지 못한 것: the operator app's 146-170 ms split and new-tab layout->applied (PRD D-12) was not reproduced in the fixture at load 28 (p50 18 ms); the remaining suspect and the next measurement are in a follow-up issue the lead opens.
  • 확인하지 못한 것: a pane close's sibling grid is proven by the page clock and by drawn_ms preceding herdr_ack_ms, not by a PTY-side read; the fixture's close ack is 36 ms, not the 0.7-4.3 s the operator saw.
  • 확인하지 못한 것: a divider drag has no fixture scenario; its frame watch is registered at request time and is covered by the zoom test's path only.
Verification record
  • PRD: agents/prd/grid-ahead-of-herdr/prd.md (sha256 d297b23b6fc270cf96e410bfcb6a81adf775e7a9cbd73fb6b85b1da7a45bcf1f)
  • Base 7f02ba5 → head c3ca056, verified 2026-10-16T15:10:33.388Z: PASS
  • Verification report: agents/runs/grid-ahead-of-herdr/verification-report.json and agents/runs/grid-ahead-of-herdr/verification-report.md; source fingerprint d6f3d096ef55aca1a20af4d5c9ba0183736a567b9bbbb4babff8e1f69fde2cc1
  • Suites:
    • S1: GREEN bash scripts/verify-cargo.sh test (exit 0)
    • S2: GREEN bash scripts/verify-cargo.sh lint (exit 0)
  • Reviews:
    • Fidelity: reviewed 89e184d, 2bdedef and c3ca056 (closure, code read only). Fix now: stale grid-hold text in ARCHITECTURE.md and events.rs (fixed, 2bdedef); the before/after cited the operator log against the fixture (fixed, same-fixture runs cited above); the cwd-answer skip could leave a pane at its sibling's folder (fixed, c3ca056); the before run's build was unnamed (fixed, Evidence names 0.4.1-main.e8c08186 by its hided sha256, closure confirmed); the D-12/B12 follow-up issue was not opened (stands, the lead opens it at ship time). Follow-up improvements: no PTY-side evidence for a close's sibling grid; the one-resize-per-operation guard is asserted for zoom only, chains unobserved; the contract test splits before attaching and has no divider resize; observed (non-controller) panes reattach instead of resizing, unstated in UI_BEHAVIOR.md; no divider-drag fixture; a chained operation can take an earlier operation's resize for its frame; the Windows branch of the contract test asserts frame sizes only.
    • Code: reviewed 89e184d, 2bdedef and c3ca056. Fix now: the contract test judged every frame, which could fail on Windows on a queued old-size frame (fixed, 2bdedef judges the marker frame only); stale force comments in events.rs and terminal.rs (fixed, 2bdedef); the cwd-answer skip left a stand-in on screen when the announced cwd differed (fixed, c3ca056, closure confirmed). Follow-up improvements: two timing records on one pane share a resize; the unchanged-grid incomplete case is not asserted; no shell-layer test that a drawn zoom reports a resize before Herdr confirms; the contract test reads the PTY size at one instant.
  • Evidence: none registered separately.
  • Changed paths: 25 (see Files changed)
  • Delivery: mode pr, branch grid-ahead-of-herdr, base main

The core held a pane's PTY size while its tab was drawn ahead of Herdr and
sent it only once Herdr's layout confirmed the drawing, so a zoom reflowed
the terminal about 150 ms after the request and a pane close left its
sibling at the old grid until Herdr's close answer (0.7 to 4.3 s measured).
The hold rested on the belief that Herdr sizes the PTY from the layout it
applied; on the pinned Herdr 0.9.3 the PTY is the controller's size alone,
through a split, a sibling's close and a zoom, so the hold had nothing to
protect against.

- Delete the grid hold: the core sends every changed view size to the
  pane's node at once, the terminal snapshot no longer carries grid_held,
  the shell no longer keeps a held grid set, and the node link's Resize
  carries no force flag.
- A pane operation's timing record counts the resized pane's first frame
  after its resize went out rather than after Herdr applied the layout;
  the record's fields and stage names are unchanged.
- Rewrite the pane geometry tests to the new contract: one resize at the
  drawing, none when Herdr confirms the same layout, one more when it
  differs, none for a size the pane already runs at.
- Add the contract test on the pinned Herdr asserting the controller's PTY
  size survives a zoom and a sibling's close, so a pin bump learns when
  that changes.
- State the new contract in ARCHITECTURE.md, UI_BEHAVIOR.md,
  PERFORMANCE_TESTING.md and AGENTS.md.
The pane zoom chord moved to ⇧⌘↩ with the right-lane expand chord, but the
topology measurement still pressed ⌥⌘↩, so every zoom and unzoom sample
timed out and the nightly's zoom latency row has been empty since.
A split or a new tab publishes at once with a sibling's cwd, or the tab's
checkout, standing in for the pane's unconfirmed cwd, and the worker's
pane.get answer then republished the whole projection even when it only
confirmed that stand-in: at operator scale on the topology fixture, 21 of
21 answers changed nothing and each cost a full publish. The answer now
publishes only when it moved a cwd or the publish before it was held for
the pane it answers; the coordinator's publish state remembers that hold.
The frame watch of a geometry operation starts when the resized pane's
PTY size goes out. A resize sent before the operation's layout was
drawn belongs to the pane's previous size and must not start the watch,
so the timing record now requires the drawn stage as well as the resize.

The pinned-Herdr contract test judged every frame a step produced, and
a frame queued before the resize still carried the old size. It now
types a marker after each step (on Unix with the PTY's own stty size)
and judges only the frame that shows it, so the test holds on every
operating system in the os contract lane.

Stale comments that still described the force flag and the grid hold
are removed from events.rs, terminal.rs and ARCHITECTURE.md.
A pane split beside a confirmed one is shown at that sibling's cwd until
Herdr confirms its own. The answer that confirms the cwd the pane was
announced with changes nothing in the replica, so the publish skip added
for D-12 left the pane at the sibling's folder on the screen whenever the
two differed. The catalog state now keeps the stand-ins the last publish
showed, bounded by the unconfirmed-cwd cap, and the answer publishes
when any of them is not the cwd the replica holds for that pane.

A timing record's resize starts its frame watch once the shell has the
layout, drawn ahead or applied from Herdr, so an operation with no
prediction still completes.
@yansfil

yansfil commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up for D-12/B12 (split and new-tab layout→applied on the operator's app, not reproduced by the fixture): with-hide/hide-private#42.

@yansfil
yansfil merged commit ec64ab0 into main Oct 16, 2026
22 checks passed
@yansfil
yansfil deleted the grid-ahead-of-herdr branch October 16, 2026 15:44
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