Files
orca/tests/e2e/in-app-typing-diagnostic.ts
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

44 lines
1.3 KiB
TypeScript

import type { Page } from '@stablyai/playwright-test'
type TypingDiagnosticWindow = Window & {
__orcaTypingDiagnostic?: {
start: () => string
stop: () => string
report: () => unknown
}
}
/** Runs the shipped renderer probe beside the bench: it splits the renderer-side phases the PTY sidecar cannot see. */
export async function withInAppTypingDiagnostic<T>(
page: Page,
enabled: boolean,
run: () => Promise<T>
): Promise<{ result: T; report: unknown }> {
if (!enabled) {
return { result: await run(), report: null }
}
const started = await page.evaluate(() => {
const target: TypingDiagnosticWindow = window
return target.__orcaTypingDiagnostic?.start() ?? null
})
if (started === null) {
return { result: await run(), report: { available: false } }
}
try {
const result = await run()
const report = await page.evaluate(() => {
const target: TypingDiagnosticWindow = window
target.__orcaTypingDiagnostic?.stop()
return target.__orcaTypingDiagnostic?.report() ?? null
})
return { result, report }
} finally {
await page
.evaluate(() => {
const target: TypingDiagnosticWindow = window
target.__orcaTypingDiagnostic?.stop()
})
.catch(() => undefined)
}
}