Repository navigation
Fast-path the CSI introducer in StateMachine::ProcessString - #20974
Clint Rutkas (crutkas) wants to merge 1 commit into
Conversation
When the ground-state print scan stops on ESC [, enter Escape and CsiEntry directly instead of feeding both characters through ProcessCharacter. Only for the output engine in ANSI mode with parser tracing off. Both entry actions run and the raw prefix is kept for passthrough, so behavior doesn't change. Adds ParserTracing::IsEnabled(), the provider check AddSequenceTrace already does inline. The TraceCharInput change adds the identical helper. Adds tests for CSI sequences split at every offset across two writes, including passthrough and the OnCsiComplete callback.
| if (_state == VTStates::Ground && | ||
| string.size() - i >= 2 && | ||
| til::at(string, i) == AsciiChars::ESC && | ||
| til::at(string, i + 1) == L'[' && | ||
| !_isEngineForInput && | ||
| _parserMode.test(Mode::Ansi) && | ||
| !_trace.IsEnabled()) |
There was a problem hiding this comment.
What is the perf improvement of this change alone? The PR description does not establish whether this individual change results in a significant improvement.
My 50ct are that we should rewrite the VT parser from a push to a pull parser, as this is easier to unit test, fuzz, and to optimize. However, this requires a major rewrite.
There was a problem hiding this comment.
Fair. Measuring it alone, will post the number. If it's noise I'll close it. Agree a pull parser is the real fix.
There was a problem hiding this comment.
Measured it alone vs main: sgr +7.6% throughput, -7.0% CPU; cursor +7.7%, -7.5%; seq flat. Table's in the description. Keeping it.
There was a problem hiding this comment.
However, the way this is written both leaves perf on the table and is also written in a somewhat odd way. I think this isn't a bad idea per se due to how common CSIs are but I'd like to see this cleaned up.
975826d to
712ca77
Compare
Summary of the Pull Request
When the ground-state print scan stops on
ESC [, enter Escape and CsiEntry directly instead of feeding both characters throughProcessCharacter. Only the output engine in ANSI mode with tracing off takes this path; entry actions and the passthrough prefix are unchanged. New tests split CSI sequences at every offset.References and Relevant Issues
One of 8 perf PRs; numbers for the whole set are in #20973.
Detailed Description of the Pull Request / Additional comments
This PR alone vs main 9a8127f (Hyper-V VM, WARP, Release x64, no PGO, 12 interleaved rounds, 24 rows per arm per mode; median Δ, 95% bootstrap CI, Mann-Whitney p; CPU is WindowsTerminal + OpenConsole per MiB):
Memory: median peak working set and private bytes of both processes moved by at most 0.4%.
Validation Steps Performed
Release x64 build with only this commit on main; TAEF: til 278/279, TextBuffer 13/13, ConParser 762/763 (1 skipped), ConAdapter 414/414, Conhost 5106/5107 (1 skipped), Terminal.Core 59/59. EnvTests::Generate fails on main too.
PR Checklist