mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-02 05:39:05 +00:00
After the CSI dispatch fast paths, profiling showed the remaining escape-sequence cost was the per-byte plumbing itself: for every parameter byte of a sequence like "ESC [ 38;2;10;20;30 m" the stream re-entered nextNonUtf8, re-checked the parser state, and re-dispatched through the fast-path switch, paying call and state check overhead per digit. consumeUntilGround now hands whole input slices to a new consumeCsiParams loop whenever the parser is in the csi_param state. It consumes runs of digits and separators with the parser accumulator state held in locals, dispatches directly when it reaches the final byte, and returns to the general path on the first byte it doesn't understand (C0 controls, intermediates, etc.), guaranteeing byte-for-byte identical semantics with the per-byte fast path it hoists. Like the dispatch fast paths, this is disabled at comptime for handlers that declare vtRaw so the inspector continues to observe every action. Throughput measured with ghostty-bench terminal-stream (full terminal handler, 100 MB deterministic corpora, 120x80, M4 Max, ReleaseFast, hyperfine means of 10 runs): | stream | before | after | change | |--------|--------|--------|--------| | csi | 525 ms | 407 ms | +29% | | sgr | 414 ms | 294 ms | +41% | Combined with the previous commit, CSI-heavy streams are 1.5-1.7x faster end to end than before this series.