Terminal feed: message-task yields, slices sized to speed, one show per frame

- On the web a turn yields through a MessageChannel task: a chain of
  zero-length timers is clamped to 4 ms each, which left the emulator
  idle for a third of a burst.
- Slices are cut to what the measured speed writes in the budget left,
  so a turn ends near 6 ms however costly the output is to parse; the
  first write takes 4 Ki units to measure.
- Writes no longer notify the view each: the feed shows the emulator's
  state once everything queued is written, and while output still waits
  after a turn at most every 32 ms, so a flood draws its final state per
  frame instead of a frame per turn.
- Stream bench: producer follows a flow window (256 KiB past drawn, 32 KiB
  frames, rate by elapsed time), reports time spent parsing, ?show=each
  for the old per-write notify; tool/perf/terminal_stream_profile.mjs
  prints a CPU profile of one workload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 02:52:41 +00:00
parent f7ef4d1445
commit ae07fe14db
8 changed files with 328 additions and 21 deletions
@@ -47,7 +47,7 @@ class ChatShellTerminalSession {
ChatShellInputHandler(optionAsMeta: this.optionAsMeta),
defaultInputHandler,
]);
_feed = ChatShellTerminalFeed(_write);
_feed = ChatShellTerminalFeed(_write, show: terminal.notifyListeners);
// Drawn at the process's own size until a view lays it out at its own.
if (run.cols > 0 && run.rows > 0) terminal.resize(run.cols, run.rows);
terminal.onOutput = _output;
@@ -185,7 +185,7 @@ class ChatShellTerminalSession {
_replaying = replay;
_drawing = !replay;
try {
terminal.write(text);
terminal.write(text, notify: false);
} finally {
_replaying = false;
_drawing = false;