Files
pipelines/app/tool/perf/terminal_stream_bench.mjs
T
alan 018d37f103 Terminal: grapheme-aware widths, drawn box/Powerline glyphs, line pictures
Emulator (vendored xterm):
- Widths follow glibc wcwidth on generated Unicode 16 tables
  (tool/gen_unicode_tables.py); combining marks, variation selectors,
  ZWJ sequences, skin tones, flags and Hangul jamo join the previous cell,
  stored as interned clusters (CellContent.clusterFlag) and drawn and
  copied whole. U+FE0F and flags take two columns, as modern terminals
  do; a wide character never starts in the last column.
- Box drawing, block elements and Powerline separators are drawn as
  geometry filling the cell; rows are whole pixels high.
- Backgrounds merge per colour; each line is a picture reused until the
  line changes (BufferLine.version); a line drawn unchanged settles into
  one laid out paragraph with a span per style. TerminalStyle and
  TerminalTheme compare by value.

App: bundled Symbols Nerd Font Mono subset (568 KiB, MIT) as the
terminal's first fallback, loaded on first use; line height 1.1;
?terminalUnicode=1 fixture showcase; bench gains a progress workload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 01:14:48 +00:00

75 lines
3.1 KiB
JavaScript

#!/usr/bin/env node
// Streams generated output through the terminal bench build
// (tool/perf/terminal_stream_bench.dart) in headless Chrome and prints one
// JSON line per workload: Flutter frame build/raster quantiles, rAF
// intervals measured in the page, and the throughput reached.
//
// node tool/perf/terminal_stream_bench.mjs --build build/terminal-bench \
// [--workloads seq,yes,unicode,colors,screen,progress] [--mb 30] [--rate 30] [--size 1280x800]
import { parseArgs } from 'node:util';
import { setTimeout as delay } from 'node:timers/promises';
import { openBrowser } from '../capture/browser.mjs';
import { serveBuild } from '../capture/serve.mjs';
const { values: options } = parseArgs({
options: {
build: { type: 'string' },
workloads: { type: 'string', default: 'seq,yes,unicode,colors,screen,progress' },
mb: { type: 'string', default: '30' },
rate: { type: 'string', default: '30' },
size: { type: 'string', default: '1280x800' },
timeout: { type: 'string', default: '120000' },
params: { type: 'string', default: '' },
},
});
if (!options.build) throw new Error('--build required');
const [width, height] = options.size.split('x').map(Number);
const quantiles = (values) => {
const sorted = [...values].sort((a, b) => a - b);
const at = (q) => sorted[Math.round(q * (sorted.length - 1))] ?? 0;
const r = (v) => Math.round(v * 100) / 100;
return { p50: r(at(0.5)), p90: r(at(0.9)), p99: r(at(0.99)), max: r(sorted.at(-1) ?? 0) };
};
const server = await serveBuild(options.build);
const browser = await openBrowser();
const evaluate = async (expression) => {
const r = await browser.send('Runtime.evaluate', { expression, returnByValue: true });
return r.result.value;
};
try {
await browser.send('Page.enable');
await browser.send('Runtime.enable');
for (const workload of options.workloads.split(',')) {
const url = new URL('/', server.origin);
url.searchParams.set('workload', workload);
url.searchParams.set('mb', options.mb);
url.searchParams.set('rate', options.rate);
for (const [k, v] of new URLSearchParams(options.params)) url.searchParams.set(k, v);
await browser.send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false });
await browser.send('Page.navigate', { url: url.href });
await delay(300);
await evaluate(`(() => {
window.__raf = [];
let last = performance.now();
const tick = (t) => { window.__raf.push(t - last); last = t; if (!window.__benchResult) requestAnimationFrame(tick); };
requestAnimationFrame(tick);
return true;
})()`);
const deadline = Date.now() + Number(options.timeout);
let result = null;
while (!result && Date.now() < deadline) {
await delay(500);
result = await evaluate('window.__benchResult ?? null');
}
if (!result) throw new Error(`${workload}: no result before the timeout`);
const raf = await evaluate('window.__raf');
// Skip the start-up frames before streaming starts.
console.log(JSON.stringify({ ...JSON.parse(result), pageRaf: quantiles(raf.slice(50)) }));
}
} finally {
await browser.close?.();
await server.close?.();
}