Repository navigation
fix(terminal): lay out sustained output incrementally - #869
Merged
Merged
Conversation
Continuous /ps refreshes rewrapped the whole 2MiB retention whenever new output arrived, and small-chunk eviction shifted both chunk arrays. Extend only the appended tail and the lines dropped from the head, and coalesce output-only list repaints. Co-authored-by: tt-a1i <[email protected]>
tt-a1i
marked this pull request as ready for review
October 16, 2026 14:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #836. Tracking context: #841.
/psdetail already coalesced output-driven repaints to 50ms and reused a layout whentotalBytesdid not change. Any new chunk changed that version, so the next render split, sanitized, and wrapped the entire retained stream — up to 2MiB — before taking the visible rows. At the same time, head eviction usedArray.prototype.shift()on both the raw and model-safe chunk arrays, and the terminal list requested a render on every output notification.Value
Under sustained output the per-refresh cost now follows the new tail and the lines dropped from the head, instead of the whole retention. A chatty process can keep the 50ms repaint budget, and small-chunk eviction no longer slides a 32k-element array on every write. List output bursts share one repaint; status changes still render immediately. UTF-8 boundaries, cross-chunk ANSI, carriage-return progress lines, and the model-safe projection are unchanged.
Approach
OutputBufferevicts with a head index and compacts the dead prefix in batches.view().textstays lazy, andslice()can read a tail without joining the retained history.truncatedChars/retainedCharsare the code-unit cursors the layout uses./pslist coalesces output-only notifications at the same 50ms delay and renders lifecycle changes (status, errors, membership) immediately.bg_watchchunk delivery, settlement, and result delivery are untouched because coalescing is local to the dashboard subscription.Validation
Runtime for every number below: Node v22.23.3, linux x64, this checkout. Input: the issue's ASCII row (
log output plain ascii 1234567890× 3 + newline, 100 columns) and 64-byte chunks. Samples are single-threadedperformance.now()timings, not a Pi TUI CPU or keyboard-latency measurement.Before (full
buildOutputLines/shift()eviction):buildOutputLines, 7 callsbuildOutputLines, 7 callsAfter (same inputs on the final revision):
buildOutputLines, 7 callsbuildOutputLinesof the retained textbun run checkpassed.bun run testpassed: 2662 Node tests and 1520 Vitest tests, 0 failures. CI run 38911816912 completed with conclusion success oneb459a0641e45f894445ad9f2710d52ce070f27c. No real Pi TUI CPU or input-latency measurement.Impact
/psdetail still tails, scrolls, resizes, switches stdout/stderr, and shows the truncation note plus spill path. Output-only list updates may wait up to 50ms; status changes do not.OutputViewgainstruncatedChars,retainedChars, andslicefor in-memory layout.