Repository navigation
perf(server): smooth sustained terminal output - #33324
StiensWout wants to merge 3 commits into
Conversation
Sustained terminal output reached clients as one RPC chunk per PTY callback, so clients spent their frame budget processing messages. terminalOutputStream now emits the first output and output after idle immediately, and holds output that follows an emission until a fixed 2 ms deadline that arrivals never move. A pending lifecycle event, snapshot or full 64 KiB batch flushes early. Events stay unmerged and in order; the ACK window, 8 MiB queue and resync are unchanged, and every wait restarts the pull so overflow is rechecked. Candidate for paired production measurement, not yet a shipping claim. Co-authored-by: GPT 6.1 Sol <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: GPT 6.1 Sol <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Grok 4.7 <[email protected]>
Use Effect monotonic time for the fixed 2 ms deadline. Extend the existing public stream test with a backward wall-clock correction; it fails before this change and passes with the original deadline afterwards. Co-authored-by: GPT 6.1 Sol <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Grok 4.7 <[email protected]>
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Terminal output is batched within a 2 ms window to smooth sustained delivery, while lifecycle events and full batches flush immediately. Existing queue limits and resynchronization remain intact, limiting the change to output-delivery timing. You can add or adjust custom eligibility rules. Learn more. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Note Written by Verified in a real dev environmentverified unchanged head ran the same 6,000-line ansi/unicode producer through the terminal input on both heads and reconstructed the received main delivered 4,220 output events in 3,664 rpc chunks, with 3,326 single-event chunks. the pr delivered 5,367 output events in 2,311 chunks, with 392 single-event chunks. pty callback counts vary between runs; this verifies batching and integrity, not a frame-rate or cpu improvement. also exercised hide/show while output continued, idle input after draining, final output immediately before exit, and reopening the terminal. the final tail arrived before
before, main: after, exact pr head: short runtime and check transcript. inspected the captures and checked uploaded video playback and seeking. Not verifiednative mobile and electron shells, macos/windows, remote/relay/tunnel connections, hardware-gpu behavior, frame/cpu performance claims, long-running memory behavior, and live slow-client overflow. queue/overflow behavior was covered by the existing focused tests. the vm transmitted emoji bytes exactly, but its terminal font displayed a fallback glyph on both versions. |



Sustained terminal output could deliver an RPC chunk for each PTY callback, making frame delivery uneven. A fixed 2 ms leading-edge window now batches adjacent output events while preserving their bytes and sequence. Idle output is immediate; lifecycle events and a full 64 KiB batch flush early. The ACK window, bounded queue and resync behavior are unchanged.
Five alternating equal-work production-build pairs on one clean VM support smoother frames with no demonstrated change in renderer CPU. During comparable active-load intervals, the median paired reduction in mean frame interval was 25.9%, long-frame share fell 54.6%, and render submissions per second rose 36.2% (higher in all five pairs). These are animation-frame/canvas observations, not compositor presentations.
Each arm completed the same 29,360,128-byte ANSI payload, offered at 4 MiB/s, on a 212×44 terminal. Main payload hashes matched, full streams matched their own producers, sequences stayed ordered, all 26 sustained echoes painted, queues drained to zero, and no resync occurred. Actual completion was about 2 MiB/s. Marker and echo overhead were accounted separately. Frame windows use the shorter active interval in each pair; CPU covers the whole equal-work sample. Repeated-run variation is shown in the graph. Full comparison and method.
The observed benefit is smoother output with no demonstrated CPU change; these samples do not establish CPU equivalence. Renderer CPU changed +0.7% (middle half −4.9% to +8.6%); page TaskDuration changed −7.3% with variation spanning zero. There is no CPU-saving claim. The original approximately 20% message-family CPU/wall acceptance criterion was not met: one separate attribution pair measured family thread CPU 1,509→1,524 ms and wall 2,598→2,787 ms, including nested terminal writes. Fewer socket tasks alone are not a speedup. Traced responsiveness is not pooled with the lean headline runs. Echo p50 improved, but echo p95 was inconsistent.
Four measured pairs have complete idle echoes. The original fifth baseline idle marker was not captured, so its idle percentile remains missing. A separate bounded 212×44 functional check recorded all 26 real key reads, emits, decoded payloads and canvas draws on both versions; it does not replace the missing measured sample or establish decode-to-paint timing.
Measured sources were base b07fdeb and candidate 740c395995cd. Rebases onto main 4c8eb1d preserved the measured patches by range-diff. The final rebase also preserved the clock fix exactly; final head is 6677da5. Final review changed the deadline clock to Effect monotonic time: both APIs use the same high-resolution monotonic source under stable wall time, and the fix removes wall-clock reanchoring without changing the 2 ms interval or timer machinery. A backward-clock test failed before that fix and passes now. The graph is captured evidence for the measured candidate, not a new benchmark of the final SHA.
Validation: focused OutputProtocol/Manager tests (94) and RpcAuthorization tests (20), primary integrated test-t3-app pass with ANSI/Unicode output and terminal hide/show, and check:changed. Standard pipeline because the change adds deadline/lifecycle state. No Manager production change or protocol/schema change. The shared server stream applies to web, Electron, native mobile and remote connections; hardware-GPU, Electron-shell, native-mobile, many-stream concurrency and remote/relay/tunnel performance were not measured. Heap endpoints were captured; peak resident memory and long-duration leak behavior were not measured. Compact frame/echo records, producer receipts and metric endpoints are retained; full wire captures are absent, so collection-time receiver hashes cannot be rehashed offline. Linux Chromium 141 used SwiftShader.
Council review
Two code rounds, followed by one same-head scope clarification. Final scores are 9/10 from all three reviewers on 0cbc070ac6. Final head 6677da5 rebases those same three patches without changes onto main 4c8eb1d; only an unrelated orchestration fix advanced upstream. The clock fix resolved the initial code finding. Grok retained an 8 while counting the failed original CPU target against shipping, then explicitly corrected that inconsistency under the revised frame-smoothing scope; the code and measurements did not change.
Fresh final-head cubic review: no issues. Its earlier Manager-test clock warning was rejected: the suite explicitly sets excludeTestServices, and the exact flagged test passes. No design-lens follow-ups. Final proof audit accepts with disclosed limits and no additional gap-fill required. Red/green evidence reobserved all five new stream cases against the old protocol and the clock correction against the wall-clock variant; restored head passes.
Created with Claude Opus 5.5 (builder and trimmer), GPT 6.1 Sol (lead, fixes, review and proof audit), and Grok 4.7 (evidence and review) in T3 Code using the Codex, Claude Agent and Grok harnesses.