From 1defc2d1dda4bbc24ba0f26d20a3492772a0fca3 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 7 Jun 2026 08:08:04 -0700 Subject: [PATCH] Summarize terminal perf benchmark reports (#4795) --- .../summarize-terminal-perf-report.mjs | 101 ++++++++++++++++++ package.json | 1 + 2 files changed, 102 insertions(+) create mode 100644 config/scripts/summarize-terminal-perf-report.mjs diff --git a/config/scripts/summarize-terminal-perf-report.mjs b/config/scripts/summarize-terminal-perf-report.mjs new file mode 100644 index 000000000..4d9e87160 --- /dev/null +++ b/config/scripts/summarize-terminal-perf-report.mjs @@ -0,0 +1,101 @@ +import { readFileSync } from 'node:fs' +import { basename } from 'node:path' + +const reportPaths = process.argv.slice(2) +if (reportPaths[0] === '--') { + reportPaths.shift() +} + +if (reportPaths.length === 0) { + console.error( + 'Usage: node config/scripts/summarize-terminal-perf-report.mjs ...' + ) + process.exit(1) +} + +function readJsonReport(path) { + const raw = readFileSync(path, 'utf8') + const start = raw.indexOf('{') + const end = raw.lastIndexOf('}') + if (start === -1 || end <= start) { + throw new Error(`${path}: no JSON object found`) + } + return JSON.parse(raw.slice(start, end + 1)) +} + +function parseAnnotationDescription(description) { + const values = {} + for (const part of description.split(/\s+/)) { + const index = part.indexOf('=') + if (index === -1) { + continue + } + values[part.slice(0, index)] = part.slice(index + 1) + } + return values +} + +function collectTerminalPerfRows(report, source) { + const rows = [] + const visitSuite = (suite) => { + for (const spec of suite.specs ?? []) { + for (const test of spec.tests ?? []) { + for (const annotation of test.annotations ?? []) { + if (!annotation.type.startsWith('opencode-')) { + continue + } + rows.push({ + source, + scenario: annotation.type, + ...parseAnnotationDescription(annotation.description ?? '') + }) + } + } + } + for (const child of suite.suites ?? []) { + visitSuite(child) + } + } + for (const suite of report.suites ?? []) { + visitSuite(suite) + } + return rows +} + +function markdownCell(value) { + return String(value ?? '').replaceAll('|', '\\|') +} + +function printMarkdownTable(rows) { + const columns = [ + ['Source', 'source'], + ['Scenario', 'scenario'], + ['Panes', 'panes'], + ['Frames', 'frames'], + ['Median', 'median'], + ['Worst', 'worst'], + ['Max Drift', 'maxTimerDrift'], + ['Hidden Skips', 'hiddenSkips'], + ['Hidden Chars', 'hiddenSkippedChars'], + ['Foreground Enqueues', 'deferredForegroundEnqueue'], + ['Foreground Writes', 'deferredForegroundWrite'], + ['Drains', 'scheduledDrains'] + ] + + console.log(`| ${columns.map(([label]) => label).join(' | ')} |`) + console.log(`| ${columns.map(() => '---').join(' | ')} |`) + for (const row of rows) { + console.log(`| ${columns.map(([, key]) => markdownCell(row[key])).join(' | ')} |`) + } +} + +const rows = reportPaths.flatMap((path) => + collectTerminalPerfRows(readJsonReport(path), basename(path)) +) + +if (rows.length === 0) { + console.error('No OpenCode terminal perf annotations found.') + process.exit(1) +} + +printMarkdownTable(rows) diff --git a/package.json b/package.json index 8c3a5d64b..93dfa9958 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "test:e2e": "pnpm run ensure:electron-runtime && npx playwright test --config tests/playwright.config.ts --project electron-headless", "test:e2e:terminal-perf": "pnpm run ensure:electron-runtime && npx playwright test tests/e2e/terminal-typing-latency.spec.ts tests/e2e/terminal-foreground-redraw-freeze.spec.ts tests/e2e/terminal-output-scheduler.spec.ts tests/e2e/terminal-hidden-tui-visual-restore.spec.ts tests/e2e/artificial-opencode-terminal-load.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=2", "test:e2e:terminal-perf:scale": "pnpm run ensure:electron-runtime && node config/scripts/run-terminal-scale-perf-e2e.mjs", + "test:e2e:terminal-perf:summarize": "node config/scripts/summarize-terminal-perf-report.mjs", "test:e2e:ssh-docker-perf": "node config/scripts/run-ssh-docker-perf-e2e.mjs", "test:e2e:headful": "pnpm run ensure:electron-runtime && npx playwright test --config tests/playwright.config.ts --project electron-headful", "test:e2e:computer": "vitest run --config tests/e2e/vitest.config.ts"