mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
* 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
217 lines
8.0 KiB
TypeScript
217 lines
8.0 KiB
TypeScript
import type { Page } from '@stablyai/playwright-test'
|
|
import {
|
|
normalizeAccumulatedWorkspaceFixtureOptions,
|
|
type AccumulatedWorkspaceFixtureOptions
|
|
} from './accumulated-workspace-profile'
|
|
import { buildAccumulatedWorkspaceSeed } from './accumulated-workspace-state-builder'
|
|
|
|
export type { AccumulatedWorkspaceFixtureOptions }
|
|
|
|
export type AccumulatedWorkspaceFixtureSummary = {
|
|
repositories: number
|
|
worktrees: number
|
|
terminalTabs: number
|
|
unifiedTabs: number
|
|
terminalLayouts: number
|
|
splitPanes: number
|
|
parkedRecords: number
|
|
lineageRecords: number
|
|
liveStatuses: number
|
|
serializedBytes: Record<string, number>
|
|
}
|
|
|
|
type FixtureWindow = Window & {
|
|
__accumulatedFixtureCleanup?: () => void
|
|
__orcaBenchmarkInstrumentation?: {
|
|
reset: () => void
|
|
start: () => void
|
|
stop: () => void
|
|
snapshot: () => unknown
|
|
}
|
|
}
|
|
|
|
/** Seeds a production-scale accumulated profile without mounting synthetic PTYs. */
|
|
export async function seedAccumulatedWorkspaceFixture(
|
|
page: Page,
|
|
options: AccumulatedWorkspaceFixtureOptions = {}
|
|
): Promise<AccumulatedWorkspaceFixtureSummary> {
|
|
const config = normalizeAccumulatedWorkspaceFixtureOptions(options)
|
|
const seed = buildAccumulatedWorkspaceSeed(config)
|
|
return page.evaluate(
|
|
({ config, seed, fullAgentRows }) => {
|
|
const store = window.__store
|
|
if (!store) {
|
|
throw new Error('store unavailable')
|
|
}
|
|
const target: FixtureWindow = window
|
|
const before = store.getState()
|
|
const settings = before.settings
|
|
if (!settings) {
|
|
throw new Error('settings unavailable')
|
|
}
|
|
const worktreesByRepo = { ...before.worktreesByRepo, ...seed.worktreesByRepo }
|
|
store.setState((current) => ({
|
|
...(fullAgentRows
|
|
? {
|
|
worktreeCardProperties: ['status', 'inline-agents'],
|
|
agentActivityDisplayMode: 'full' as const
|
|
}
|
|
: {}),
|
|
repos: [...current.repos, ...seed.repos],
|
|
worktreesByRepo,
|
|
tabsByWorktree: { ...current.tabsByWorktree, ...seed.tabsByWorktree },
|
|
ptyIdsByTabId: { ...current.ptyIdsByTabId, ...seed.ptyIdsByTabId },
|
|
terminalLayoutsByTabId: {
|
|
...current.terminalLayoutsByTabId,
|
|
...seed.terminalLayoutsByTabId
|
|
},
|
|
unifiedTabsByWorktree: {
|
|
...current.unifiedTabsByWorktree,
|
|
...seed.unifiedTabsByWorktree
|
|
},
|
|
groupsByWorktree: { ...current.groupsByWorktree, ...seed.groupsByWorktree },
|
|
activeGroupIdByWorktree: {
|
|
...current.activeGroupIdByWorktree,
|
|
...seed.activeGroupIdByWorktree
|
|
},
|
|
layoutByWorktree: { ...current.layoutByWorktree, ...seed.layoutByWorktree },
|
|
sleepingAgentSessionsByPaneKey: {
|
|
...current.sleepingAgentSessionsByPaneKey,
|
|
...seed.sleepingAgentSessionsByPaneKey
|
|
},
|
|
worktreeLineageById: {
|
|
...current.worktreeLineageById,
|
|
...seed.worktreeLineageById
|
|
},
|
|
settings: {
|
|
...settings,
|
|
tabAutoGenerateTitle: false,
|
|
compactWorktreeCards: false,
|
|
terminalScrollbackRows: 50_000
|
|
}
|
|
}))
|
|
const now = Date.now()
|
|
for (const status of seed.liveStatuses) {
|
|
for (let historyIndex = 0; historyIndex < config.statusHistoryEntries; historyIndex += 1) {
|
|
const historyRemaining = config.statusHistoryEntries - historyIndex
|
|
store.getState().setAgentStatus(
|
|
status.paneKey,
|
|
{
|
|
state: historyRemaining % 2 ? 'working' : 'waiting',
|
|
prompt: status.prompt,
|
|
agentType: 'codex'
|
|
},
|
|
'codex',
|
|
{
|
|
updatedAt: now - historyRemaining * 1_000,
|
|
stateStartedAt: now - historyRemaining * 1_000
|
|
},
|
|
{ tabId: status.tabId, worktreeId: status.worktreeId }
|
|
)
|
|
}
|
|
}
|
|
const syntheticStatuses = Object.fromEntries(
|
|
Object.entries(store.getState().agentStatusByPaneKey).filter(([paneKey]) =>
|
|
paneKey.startsWith('synthetic-tab-')
|
|
)
|
|
)
|
|
const serializedSlices = {
|
|
repos: seed.repos,
|
|
worktreesByRepo: seed.worktreesByRepo,
|
|
tabsByWorktree: seed.tabsByWorktree,
|
|
unifiedTabsByWorktree: seed.unifiedTabsByWorktree,
|
|
terminalLayoutsByTabId: seed.terminalLayoutsByTabId,
|
|
sleepingAgentSessionsByPaneKey: seed.sleepingAgentSessionsByPaneKey,
|
|
agentStatusByPaneKey: syntheticStatuses
|
|
}
|
|
const byteLength = (value: unknown): number =>
|
|
new TextEncoder().encode(JSON.stringify(value)).byteLength
|
|
const serializedBytes = Object.fromEntries(
|
|
Object.entries(serializedSlices).map(([key, value]) => [key, byteLength(value)])
|
|
)
|
|
serializedBytes.total = byteLength(serializedSlices)
|
|
target.__accumulatedFixtureCleanup = () => {
|
|
store.setState({
|
|
worktreeCardProperties: before.worktreeCardProperties,
|
|
agentActivityDisplayMode: before.agentActivityDisplayMode,
|
|
repos: before.repos,
|
|
worktreesByRepo: before.worktreesByRepo,
|
|
tabsByWorktree: before.tabsByWorktree,
|
|
ptyIdsByTabId: before.ptyIdsByTabId,
|
|
terminalLayoutsByTabId: before.terminalLayoutsByTabId,
|
|
unifiedTabsByWorktree: before.unifiedTabsByWorktree,
|
|
groupsByWorktree: before.groupsByWorktree,
|
|
activeGroupIdByWorktree: before.activeGroupIdByWorktree,
|
|
layoutByWorktree: before.layoutByWorktree,
|
|
sleepingAgentSessionsByPaneKey: before.sleepingAgentSessionsByPaneKey,
|
|
worktreeLineageById: before.worktreeLineageById,
|
|
agentStatusByPaneKey: before.agentStatusByPaneKey,
|
|
runtimePaneTitlesByTabId: before.runtimePaneTitlesByTabId,
|
|
settings: before.settings
|
|
})
|
|
delete target.__accumulatedFixtureCleanup
|
|
}
|
|
const countLeaves = (node: (typeof seed.terminalLayoutsByTabId)[string]['root']): number => {
|
|
if (!node) {
|
|
return 0
|
|
}
|
|
return node.type === 'leaf' ? 1 : countLeaves(node.first) + countLeaves(node.second)
|
|
}
|
|
return {
|
|
repositories: seed.repos.length,
|
|
worktrees: Object.values(seed.worktreesByRepo).flat().length,
|
|
terminalTabs: Object.values(seed.tabsByWorktree).flat().length,
|
|
unifiedTabs: Object.values(seed.unifiedTabsByWorktree).flat().length,
|
|
terminalLayouts: Object.keys(seed.terminalLayoutsByTabId).length,
|
|
splitPanes: Object.values(seed.terminalLayoutsByTabId).reduce(
|
|
(count, layout) => count + countLeaves(layout.root),
|
|
0
|
|
),
|
|
parkedRecords: Object.keys(seed.sleepingAgentSessionsByPaneKey).length,
|
|
lineageRecords: Object.keys(seed.worktreeLineageById).length,
|
|
liveStatuses: seed.liveStatuses.length,
|
|
serializedBytes
|
|
}
|
|
},
|
|
{ config, seed, fullAgentRows: process.env.ORCA_TYPING_BENCH_AGENT_ROWS === 'full' }
|
|
)
|
|
}
|
|
|
|
export async function startAccumulatedBenchmarkInstrumentation(page: Page): Promise<boolean> {
|
|
return page.evaluate(() => {
|
|
const target: FixtureWindow = window
|
|
const instrumentation = target.__orcaBenchmarkInstrumentation
|
|
if (!instrumentation) {
|
|
return false
|
|
}
|
|
instrumentation.reset()
|
|
instrumentation.start()
|
|
return true
|
|
})
|
|
}
|
|
|
|
export async function stopAccumulatedBenchmarkInstrumentation(
|
|
page: Page
|
|
): Promise<
|
|
| { available: true; snapshot: unknown }
|
|
| { available: false; reason: 'not-installed'; snapshot: null }
|
|
> {
|
|
return page.evaluate(() => {
|
|
const target: FixtureWindow = window
|
|
const instrumentation = target.__orcaBenchmarkInstrumentation
|
|
if (!instrumentation) {
|
|
return { available: false as const, reason: 'not-installed' as const, snapshot: null }
|
|
}
|
|
const snapshot = instrumentation.snapshot()
|
|
instrumentation.stop()
|
|
return { available: true as const, snapshot }
|
|
})
|
|
}
|
|
|
|
export async function cleanupAccumulatedWorkspaceFixture(page: Page): Promise<void> {
|
|
await page.evaluate(() => {
|
|
const target: FixtureWindow = window
|
|
target.__accumulatedFixtureCleanup?.()
|
|
})
|
|
}
|