Files
openidea/perf/lib/tuiRows.ts
T
Bruno Belloni 2738bd0ccc perf(terminal): add a full-screen TUI scenario (#2251)
The perf suite had no terminal scenario, so nothing guarded the terminal row cache (#2239) against regressions. The new terminalTui scenario streams a full-screen TUI into the terminal at 10 fps (every row rewritten, only the spinner row changed, the title updated, as agent CLIs do) while typing in an editor, through a hidden action registered only in dev and perf builds. rowsRebuiltPerTuiFrame counts row elements rebuilt per frame independently of MutationObserver batching and fails when no terminal output arrives; budget 3 (about 1.4 with the cache, the screen height without it).

Co-authored-by: brunobelloni <14021404+brunobelloni@users.noreply.github.com>
2026-11-10 02:05:33 +08:00

29 lines
1.1 KiB
TypeScript

type TuiWindow = Window & { __stopTuiRows?: () => number };
/** Runs in the page; count replacements independently of observer delivery batches. */
export function startTuiRowObserver() {
const container = document.querySelector(".xterm .xterm-rows");
if (!container?.childElementCount) throw new Error("terminal row renderer did not open");
let rebuilt = 0;
const count = (records: MutationRecord[]) => {
for (const record of records) if (record.target.parentNode === container) rebuilt++;
};
const observer = new MutationObserver(count);
observer.observe(container, { childList: true, subtree: true });
(window as TuiWindow).__stopTuiRows = () => {
count(observer.takeRecords());
observer.disconnect();
return rebuilt;
};
}
export function stopTuiRowObserver(): number {
const w = window as TuiWindow;
const stop = w.__stopTuiRows;
delete w.__stopTuiRows;
if (!stop) throw new Error("terminal row observer did not start");
const rebuilt = stop();
if (!rebuilt) throw new Error("terminal TUI did not render any rows");
return rebuilt;
}