Files
orca/config/scripts/run-multi-workspace-typing-bench.mjs
T
Jinjing 21cb9ebb78 perf(terminal): send typed keys to the PTY before publishing activity; split echo latency phases (#36008)
* perf(diagnostics): split terminal echo latency into queueing, round-trip, parse and paint phases

The typing diagnostic started timing at its own capture handler and lumped the
PTY round trip, renderer output scheduling and xterm parse into one interval, so
a stalled renderer could not be told apart from a slow PTY or TUI. Exact samples
now also report trusted-event input queueing, onData to first output reaching
the output scheduler, scheduler queueing, and xterm parse, plus each sample's
overlap with long animation frames. The report shape only gains fields.

* test(bench): measure terminal echo phases under accumulated workspace-update pressure

Adds a typing bench scenario that types into one real PTY while the accumulated
store receives rank-only order publications (and optional status traffic), runs
the in-app phase diagnostic beside the PTY sidecar, and moves the shared bench
knobs and report writer into a module both specs use.

* perf(terminal): send a typed key to the PTY before publishing its activity stamp

xterm fires onUserInput before onData, and the first key after a pause wrote
lastTerminalInputAtByPaneKey synchronously there, so the key waited on every
store subscriber before it was sent. Publish the stamp in a microtask instead:
the same task still records it, after the key has been handed to the transport.
At 1,620 workspaces and 2,356 store listeners, input-to-dispatch for keys after
a pause fell from p50 1.2-1.5 ms to 0.5 ms.

* Improve typing latency diagnostic accuracy

* Flush queued long tasks in live typing latency reports
2026-10-29 12:11:08 -07:00

83 lines
3.2 KiB
JavaScript

// Run pnpm bench:multi-workspace-typing -- --panes 8 --rate-kbps 512 --keys 48 --label before-fix (see terminal-multi-workspace-typing-latency.spec.ts).
// Save distinct labels per build/config in tests/tools/benchmarks/results/multi-workspace-typing-*.json; compare totalMs/inputHalfMs/echoHalfMs percentiles.
import { spawn } from 'node:child_process'
const npxCommand = process.platform === 'win32' ? 'npx.cmd' : 'npx'
const knobByFlag = {
'--visited-workspaces': 'ORCA_TYPING_BENCH_VISITED_WORKSPACES',
'--load-workspaces': 'ORCA_TYPING_BENCH_LOAD_WORKSPACES',
'--panes': 'ORCA_TYPING_BENCH_LOAD_PANES',
'--rate-kbps': 'ORCA_TYPING_BENCH_RATE_KBPS',
'--keys': 'ORCA_TYPING_BENCH_KEYS',
'--cadence-ms': 'ORCA_TYPING_BENCH_KEY_CADENCE_MS',
'--cpu-workers': 'ORCA_TYPING_BENCH_CPU_WORKERS',
'--git-churn-repos': 'ORCA_TYPING_BENCH_GIT_CHURN_REPOS',
'--git-churn-files': 'ORCA_TYPING_BENCH_GIT_CHURN_FILES',
'--git-churn-concurrency': 'ORCA_TYPING_BENCH_GIT_CHURN_CONCURRENCY',
'--codex-frame-rows': 'ORCA_TYPING_BENCH_CODEX_FRAME_ROWS',
'--codex-split-delay-ms': 'ORCA_TYPING_BENCH_CODEX_SPLIT_DELAY_MS',
'--worktrees': 'ORCA_TYPING_BENCH_METADATA_WORKTREES',
'--repositories': 'ORCA_TYPING_BENCH_METADATA_REPOSITORIES',
'--terminal-tabs': 'ORCA_TYPING_BENCH_METADATA_TERMINAL_TABS',
'--unified-tabs': 'ORCA_TYPING_BENCH_METADATA_UNIFIED_TABS',
'--sleepers': 'ORCA_TYPING_BENCH_METADATA_SLEEPERS',
'--live-statuses': 'ORCA_TYPING_BENCH_METADATA_LIVE_STATUSES',
'--panes-per-tab': 'ORCA_TYPING_BENCH_METADATA_PANES',
'--status-history': 'ORCA_TYPING_BENCH_METADATA_STATUS_HISTORY',
'--status-interval-ms': 'ORCA_TYPING_BENCH_METADATA_STATUS_INTERVAL_MS',
'--agent-rows': 'ORCA_TYPING_BENCH_AGENT_ROWS',
'--title-change-ms': 'ORCA_TYPING_BENCH_TITLE_CHANGE_MS',
'--lifecycle-ms': 'ORCA_TYPING_BENCH_LIFECYCLE_MS',
'--cpu-profile': 'ORCA_TYPING_BENCH_CPU_PROFILE',
'--pty-metadata': 'ORCA_TYPING_BENCH_PTY_METADATA',
'--metadata-status': 'ORCA_TYPING_BENCH_METADATA_STATUS',
'--metadata-titles': 'ORCA_TYPING_BENCH_METADATA_TITLES',
'--instrumentation': 'ORCA_TYPING_BENCH_INSTRUMENTATION',
'--graph-probe': 'ORCA_TYPING_BENCH_GRAPH_PROBE',
'--cpu-throttle': 'ORCA_TYPING_BENCH_CPU_THROTTLE',
'--order-churn-ms': 'ORCA_TYPING_BENCH_ORDER_CHURN_MS',
'--in-app-diagnostic': 'ORCA_TYPING_BENCH_IN_APP_DIAGNOSTIC',
'--label': 'ORCA_TYPING_BENCH_LABEL'
}
const env = { ...process.env, ORCA_BACKGROUND_LAUNCH: '1', ORCA_TYPING_BENCH: '1' }
const passthroughArgs = []
const argv = process.argv.slice(2)
for (let i = 0; i < argv.length; i++) {
if (argv[i] === '--') {
continue
}
const knob = knobByFlag[argv[i]]
if (knob) {
env[knob] = argv[++i]
} else {
passthroughArgs.push(argv[i])
}
}
const child = spawn(
npxCommand,
[
'playwright',
'test',
'tests/e2e/terminal-multi-workspace-typing-latency.spec.ts',
'tests/e2e/terminal-workspace-update-typing-latency.spec.ts',
'--config',
'tests/playwright.config.ts',
'--project',
'electron-headless',
'--workers=1',
...passthroughArgs
],
{ stdio: 'inherit', env }
)
child.on('exit', (code, signal) => {
if (signal) {
process.kill(process.pid, signal)
return
}
process.exit(code ?? 1)
})