Terminal emulator: faster write path (ASCII runs, reused lines, no per-char allocation)

- Parser reads the written strings directly (no rune list per write) and
  handles printable ASCII runs and C0 controls straight from the string;
  a run is written into the line in one call (Buffer.writeAscii,
  BufferLine.setAsciiCells), as writeChar would one by one.
- A line leaving a full scrollback (or a one-line region scroll) is
  cleared and reused instead of allocating a 4 KiB line; lines with
  anchors (selection ends) still leave detached. Lines track the cells
  written since made or cleared, so a clear touches only those.
- Grapheme join rejects characters that cannot join before reading the
  cell (it built a String per character); width table covers plane 1.
- Switch dispatch for C0 controls, direct calls for CSI and SGR (torn-off
  handlers are slow in JavaScript); CSI params emptied without clear();
  circular buffer index without %; insert keeps the start index wrapped.
- Terminal.write(notify: false) lets a host notify once per frame.
- tool/perf/terminal_parse_bench.dart: parse throughput in the VM or V8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 02:34:08 +00:00
parent e526150b1e
commit f7ef4d1445
13 changed files with 674 additions and 85 deletions
+6 -1
View File
@@ -23,7 +23,11 @@ class IndexAwareCircularBuffer<T extends IndexedItem> {
/// the regular index.
@pragma('vm:prefer-inline')
int _getCyclicIndex(int index) {
return (_startIndex + index) % _array.length;
// Indexes run from 0 to the capacity (one past the end when pushing),
// so one subtraction wraps them; `%` is a helper call in JavaScript.
final cyclic = _startIndex + index;
final capacity = _array.length;
return cyclic >= capacity ? cyclic - capacity : cyclic;
}
/// Removes the element at [index] from the list.
@@ -196,6 +200,7 @@ class IndexAwareCircularBuffer<T extends IndexedItem> {
if (_length >= _array.length) {
_startIndex += 1;
if (_startIndex == _array.length) _startIndex = 0;
_absoluteStartIndex += 1;
} else {
_length++;