Skip to content

fix: kitty control parsing, and snapshot and wait costs (#841 #843 #854 #856) - #889

Open
vyncint wants to merge 4 commits into
mainfrom
fix/01112-perf
Open

vyncint wants to merge 4 commits into
mainfrom
fix/01112-perf

Conversation

@vyncint

@vyncint vyncint commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Four v0.11.12 issues: kitty control parsing and two snapshot and wait costs. One commit each, each with tests that fail without the fix. The public API is unchanged, and semver-checks against main reports nothing to update.

history rows one snapshot before → after 1000-frame recording peak before → after
1,000 121 µs → 140 µs 118 → 102 MiB
32,000 606 µs → 128 µs 591 → 102 MiB
  • At the 1000x1000 limit, one full-screen paint times out the first wait_until: it snapshots after every read #854: a wait_until evaluation is spaced by its own cost. After an evaluation that took d, the next waits at least d. Every screen the wait stops on, and the last one before the deadline, is still evaluated.
    • "Skip while a read is pending" was tried first and never triggered, because the waiter wins the lock while the reader sits in read(2), so it was dropped.
    • At 1000x1000, release, one full paint now holds in 1.7–2.1 s with 12 evaluations, where it timed out at 5 s with 98–170.
    • The size() table, the MAX_DIMENSION comment and DESIGN §2 now carry measured numbers.
    • A new release-only tests/large_grid.rs pins the 1000x1000 wait to the default 5 s.

Local: the full suite passed three times (1038 tests). frames and basic passed 10 runs at 1–17 threads in debug and 5 runs in release. Stress is dispatched.

Closes #843
Closes #841
Closes #856
Closes #854

kitty's parse_graphics_code stores each value into its field as it
reads it, so a key given twice keeps its last value. termlens searched
the control block once per reader and stopped at the first pair naming
the key, and the query test matched any `a=q` in the block: `a=t,...,a=T`
was transmitted only, `c=3,...,c=5` covered three columns, `a=q,...,a=T`
was taken for a query, and `a=q,i=31,...,i=32` was answered `i=31`.

The block is now parsed once into a KittyControl, the last value of
each key winning, and every reader (the builder, the delete filter,
MidUpload, KittyAsk, the query test and the query itself) reads that.

Closes #843

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
kitty 0.49's parse_graphics_code returns before the graphics manager on
an invalid key, a flag value outside its set, a value with no digits or
past UINT32_MAX, and anything but `,` or `;` after a value, and its
REPORT_ERROR only logs. handle_add_command then refuses a load declaring
more than 10000 pixels a side. termlens read the block a key at a time
and went ahead with all of them: a trailing comma, an unknown key or a
bad flag still captured, counted and placed an image, and a malformed
query or a feature query (`e=`, a key 0.49 does not have) was answered
`OK`.

KittyControl::parse is now kitty's state machine, and an escape it
refuses is no command: its bytes are counted, and nothing else happens,
an upload in progress included. A transmission or query starting a load
over 10000 pixels a side is refused; the query gets kitty's EINVAL. `m=`
is read as kitty reads it, any nonzero value meaning more.

Closes #841

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
Every snapshot collected the retained history into a slice of its own,
one Arc clone per row, and with styled history a second slice. A wait
evaluation and a recorded DEC 2026 frame therefore cost O(history), and
each recorded frame held its own index of the history, 16 bytes a row.
On an 80x24 terminal with 32,000 rows, one snapshot took 606 us against
121 us at 1,000 rows, and 1,000 recorded frames grew the process by
591 MiB.

The emulator now keeps its history in a RowLog: sealed chunks of 256
rows and an open tail, with the HistoryRows last built from them cached
until the history changes. A snapshot with no row scrolled since the
last is one refcount; one after a scroll clones a pointer per chunk and
at most 255 rows. A snapshot at 32,000 rows now takes 128 us, and the
recording grows the process by 102 MiB at every depth. The Screen API
and its serialized form are unchanged.

The scrollback_styles and record_budget docs are corrected to what a
snapshot and a frame now hold.

Closes #856

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
wait_until evaluated its predicate on a fresh snapshot after every read,
under the state lock the reader needs for each read. A snapshot is
O(cells), about 90 ms at 1000x1000 in release, so while a wait was
pending the reader got one read of at most 8 KiB in per snapshot: one
paint of every cell of a 1000x1000 grid took 8 to 14 s to wait through,
and the first wait_until timed out at its default 5 s.

The wait now spaces its evaluations: after one that took d, the next
waits until d has passed (Monitor::wait_paced wakes it then, nothing
else need arrive), so evaluating keeps to at most half the lock's time.
Every screen the wait stops on is still evaluated, and so is the last
before the deadline. On ordinary screens d is microseconds. The paint is
now waited through in 1.7 s in release and 3.3 s in debug.

The size() table and the MAX_DIMENSION comment are measured again: a
1000x1000 snapshot costs about 90 ms in release and 620 ms in debug, not
10 ms and 297 ms. tests/large_grid.rs holds the paint to the default
timeout in release builds.

Closes #854

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment