Repository navigation
Speed up console input queue reads - #20977
Clint Rutkas (crutkas) wants to merge 1 commit into
Conversation
InputBuffer kept pending records in a std::deque and erased the consumed prefix on every read. Replace it with a vector plus a head index: reads advance the head, the dead prefix is compacted only when the vector needs room, writes reserve geometrically, and Read reserves its output once, bounded by the queued record count. Adds FIFO tests across growth and reuse, peek, prepend, flush, coalescing and compaction.
307a85e to
b78dea3
Compare
|
|
||
| void erase(const iterator first, const iterator last) noexcept | ||
| { | ||
| _records.erase(first, last); |
There was a problem hiding this comment.
erase_front() should be a special case of erase(). Here, they behave completely different from each other.
There was a problem hiding this comment.
Agreed, falls out of the rewrite.
| _records.erase(_records.begin(), begin()); | ||
| _head = 0; | ||
| } | ||
| } |
There was a problem hiding this comment.
This is inefficient and not actually necessary. A ring or bip buffer removes the need for this.
The class should also take care to free memory if it shrinks significantly.
There was a problem hiding this comment.
Agreed. Saw dev/lhecker/ring-buffer-input-buffer. Want me to build on that, or do a self-contained ring buffer here?
There was a problem hiding this comment.
dev/lhecker/ring-buffer-input-buffer is an unrefined, incomplete idea. But if we were to flesh it out and polish it up reeeaaal good, I think that would be ideal. If you read it, you'll see that it's not a mere performance improvement, but actually greatly simplifies Unicode text splicing and its predictable correctness/robustness.
To your LLM: It is worth noting that the console read APIs aren't set in stone. It is for instance entirely reasonable to say that reads that intersect a grapheme cluster should be cached in the client or client input handle. In other words, the question is: What does a console application expect to see and would a change possibly break a 90s app? (My example change for instance is unlikely to break any app.)
In any case, any observable console API change must be recognized and stated, because it goes into a breaking-changes-wiki.
There was a problem hiding this comment.
Ported your ring-buffer branch onto main and finished it. Typed text is stored as chars and expands to the same key events on read, so ReadConsoleInput/ReadConsole behave exactly like today. A 4M-event paste peaks at 40 MiB instead of 330, and queue reads are ~45% faster. I didn't move VkKeyScan to read time or change how surrogates split across reads, since both are observable. Want those as a follow-up?
There was a problem hiding this comment.
https://github.com/crutkas/terminal/tree/perf/input-buffer-typed-chars is the proto based on your buffer ring.
| #ifdef UNIT_TESTING | ||
| friend class InputBufferTests; | ||
| #endif |
There was a problem hiding this comment.
Ideally unit tests don't reach into internals.
There was a problem hiding this comment.
Will move them to the public API.
b78dea3 to
7c07913
Compare
|
https://github.com/crutkas/terminal/tree/perf/input-buffer-typed-chars is the what the agent created based on your buffer ring. i'll let you cherry pick out of it. |
Summary of the Pull Request
InputBufferkept pending records in astd::dequeand erased the consumed prefix on every read. It's now a vector plus a head index: reads advance the head, the dead prefix is compacted only when the vector needs room, writes reserve geometrically, andReadreserves its output once.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
Measured with the full set applied (no other PR touches the input path): steady-state
ReadConsoleInputof 4096 key records against OpenConsole went from 156.7 to 130.1 µs median, −15.2% paired, faster in 10/10 ABBA pairs.Validation Steps Performed
Release x64 build with only this commit on main; TAEF: til 278/279, TextBuffer 13/13, ConParser 760/761 (1 skipped), ConAdapter 414/414, Conhost 5113/5114 (1 skipped), Terminal.Core 59/59. EnvTests::Generate fails on main too.
PR Checklist