summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/next-daemon.md93
1 files changed, 93 insertions, 0 deletions
diff --git a/docs/next-daemon.md b/docs/next-daemon.md
index 903a80ad..a39484b8 100644
--- a/docs/next-daemon.md
+++ b/docs/next-daemon.md
@@ -555,3 +555,96 @@ core time p50 0.96-0.97, keystroke-to-present p50 0.98-1.03 (A/A 1-23%),
p50 1.00-1.04 (A/A 2-18%), present-bound at the window's 30 ms. Two
costs the A/B found are gone (the geometry key, the paint-ahead's
thread start in the render).
+
+## Tty throughput notes
+
+Found and fixed 2026-10-29 (`src/tty/tty.zig`, `waitInput`).
+
+- **What the 1 GB `yes` cell measures is mostly the kernel.** A pty's
+ output processing (ONLCR, a `\n` made `\r\n`) costs the writer about
+ 0.4 us a newline here, and `yes` writes one every two bytes. Every reader
+ of a pty is capped by it: `script(1)` drains 100 MB of `yes` at 8.6 MB/s
+ with OPOST on and at 650 MB/s with it off, a Python drain at 8.0 MB/s,
+ and tmux at 5.4 MB/s. The tty pardes was at 5.7 to 6.1 MB/s, three
+ quarters of that ceiling, before any change. The 179 s were the kernel's.
+- **Where pardes itself was slow:** with 200-byte lines (`yes` of a long
+ word), the ceiling rises to 264 MB/s, tmux reaches 55 MB/s, and pardes
+ managed 18.6 MB/s. A flat profile (perf at paranoid 2 allows no call
+ graphs) put 98.7% of the samples in pardes: `Vaxis.render` 29%,
+ `body_layer.renderBody` 17%, `Shell.present` 10%, memcpy 8%,
+ ghostty's parse 1.5%. The tty drew a frame for every pty read, which
+ is 4 KB, nearly all of them overwritten before anyone could see them
+ (about 690k frames for the 1 GB cell).
+- **The fix: output is drawn once per frame tick at most** (16 ms), with
+ whatever came in until then, as the GUI drains its queue once per vsync.
+ Two things are drawn at once, as before:
+ - an input's frame;
+ - the focused pane's output within a second of an input (its echo; a
+ remote shell's arrives an RTT later).
+ Neither waits while it is undrawn, including when FrameAck held its
+ frame for the terminal's answer. Snapshot runs (the virtual clock) are
+ not paced.
+- **And a pane has two reads queued at most** (`readPty`): its reader
+ waits for the loop to take one before it reads on. ghostty parses `yes`
+ at about 9 MB/s, 0.45 ms a 4 KB read, slower than this machine's pty
+ delivers it. So a flood filled the loop's queue (512 events): a key and
+ its echo waited behind its reads, and which blocked writer a free slot
+ woke was luck, which gave half-second peaks. Paced but unbounded, the
+ wait was steady at about 20 reads, 9 ms for the key and 9 more for its
+ echo. A frame dump lined up with each key's write showed it (PARDES_FRAMES
+ and `flood.py` with FRAMES=). What a flood writes beyond two reads now
+ waits in its pty; the loop could not have kept up with it anyway.
+- **Measured** (ReleaseFast, `.scratch/daemon/term/yes.py` through a real
+ 120x40 pty, all interleaved, with measurements pinned to two physical
+ cores and so four CPUs; medians of 3 rounds, MB/s):
+
+ | | `yes`, 32 MiB | 200-byte lines, 256 MiB |
+ |---|---|---|
+ | base (before the rework) | 5.5 | 14.5 |
+ | phase 1's tip | 4.8 | 15.0 |
+ | pacing alone (the queue limit came after) | 4.6 | 117 |
+ | tmux | 5.4 | 47.6 |
+ | raw pty drain (Python) | 7.7 | 239 |
+ | GUI, test mode | 0.9 | |
+
+ Unpinned, before the pinning: 200-byte lines 18.6 to 247 MB/s (1 GB in
+ 53.7 s and in 4.0 s), and `yes` 5.7 to 6.9 MB/s. The GUI could only be
+ measured in its test mode (a hidden window), which downloads every frame
+ from the GPU, so 0.9 MB/s says nothing of a real window. There is no
+ headless compositor here, and a real window must not open on the user's
+ session. In a later interleaved run, the change as committed against
+ pacing alone gave 4.8 and 6.0 against 4.8 and 5.4 MB/s for `yes`, and
+ 102 and 117 against 124 and 119 MB/s for long lines: the same within
+ the noise. `pardes-perf --live`'s `yes` cell drew 2.3k frames for 32 MiB
+ against 11k before, in the same time: it is kernel-bound.
+- **A held key while another pane floods** (`flood.py`: a key every 30
+ ms into `cat` in one pane of `-n 3`, timed from its write to the pty to
+ its echo on screen, with pyte in the loop; `yes` in another pane):
+ in one interleaved run of two rounds (p50, p90, worst, in ms):
+
+ | | under the flood | idle |
+ |---|---|---|
+ | phase 1's tip | 3.0, 212 to 214, 445 to 470 | 2.2 to 2.3 |
+ | pacing alone | 10.3 to 10.6, 19 to 20, 26 to 33 | 2.3 |
+ | this change | 3.3 to 4.2, 4.3 to 5.6, 6.0 to 7.8 | 2.3 to 3.2 |
+
+ The driver's own cost (pyte) is in every number. With 16 KiB queued a
+ pane instead of two reads, the flood's p50 was 7.5 to 7.8 ms for no
+ throughput gained, so two reads it is.
+- **Keystroke-to-present** (`pardes-perf-live --live`, base and this
+ change interleaved, 5 and 4 runs; A/A between the base runs' halves):
+ p50 against base is 0.92 for key-down, 0.89 key-right, 0.85 edit-char,
+ 0.80 page-down and 0.93 wheel. The A/A was 0.73 to 0.92. The 32 MiB
+ `yes` took 1.00 the time with 0.18 the frames, and the big open 1.10
+ (A/A 1.05). Two earlier runs of pacing alone, 3 and 5 rounds, were
+ within their A/A too.
+- **Unrelated, found on the way:** `test/fs.py` failed
+ `unattended_messages_expire` (its first `shown()`) on phase 1's tip as
+ well; pmxpuolt on main (a message's stamp and expiry read the clock
+ again) is that fix. fs.py also needs a short TMPDIR: under
+ `.scratch/daemon/term/tmp`, `directory_panes`'s socket path is 108 bytes,
+ one past the limit, and the session starts with no 9P. Two GUI unit tests
+ fail on phase 1's tip as well (`tagline pointer mapping ...`, `a tag caret
+ past its row's end ...`). A suite started as a shell's `&` job runs with
+ SIGINT ignored, so four host_io tests whose Ctrl-C must stop a `sleep`
+ fail there; started otherwise, they pass.