hex/perf/interaction.bench.ts
Luke Parker a25213285b perf: fix the model-picker case and the macOS tray launch the benches use
The model-picker case clicked Back while the picker panel still sprang to
the full list's height, so the click missed and the case timed out on
macOS. It now waits for the window to rest between views.

macOS `hex app` had no `--hidden` flag, so the benches' tray targets
(`hex app --hidden`) exited with a usage error at once and measured
nothing. `hex app --hidden` now starts in the menu bar without the window,
as on Linux and Windows, and skips the GPU prewarm.
2026-11-06 01:02:27 +10:00

90 lines
3.8 KiB
TypeScript

// Using the Settings window (docs/perf.md), driven as a person would: strobe
// finds each control in Hex's accessibility tree by its key (UI Automation's
// AutomationId) and posts mouse and key input to the window. The home holds
// a full History (seeds/history.ts). Needs an unlocked session: pointer input
// and presented frames don't reach a locked one.
import { bench, native, type Page } from "@hona/strobe"
import { historySeed } from "./seeds/history"
const home = historySeed()
// A sidebar item, clicked.
const open = (page: Page, item: string, until: string) => page.click(item, { until })
// History's list `by` pixels at 3,000 px/s.
const scroll = (page: Page, by: number) => page.scroll("history-scroll", { by, speed: 3_000 })
// The UI thread's CPU decides "does this cost less"; what reached the screen
// and how soon are the person's view of it. The GPU's share says what each
// frame costs it (macOS reports it without the Screen Recording frames need).
const ui = ["interaction.p50", "interaction.p95", "frames.dropped", "cpu.work", "gpu.process.3d", "memory.app.private"]
export default bench({
targets: {
// Each case names the pane its blocks show before and after the runs; a
// block on another screen (a first-run dialog) is refused, not timed.
window: native("hex", { home, viewport: { width: 980, height: 760 }, expect: { title: "Hex" } }),
},
// Fonts, the GPU and the first frames settle, then each case starts from
// its pane.
async setup({ page, case: name }) {
await page.waitFor("basics", { timeout: 30_000 })
await page.idle()
if (name !== "switch-panes" && name !== "model-picker") {
await open(page, "nav-history", "history-list")
await page.idle()
}
},
cases: {
// General → History (200 rows of 10,000) → Output → General.
"switch-panes": {
expect: { heading: "General" },
primary: "ui.cpu",
metrics: ui,
async run({ page }) {
await open(page, "nav-history", "history-list")
await open(page, "nav-output", "output-content")
await open(page, "nav-general", "basics")
},
},
// Down History's list and back, at a trackpad's pace.
"history-scroll": {
expect: { heading: "History" },
primary: "ui.cpu",
metrics: ["scroll.latency.p50", "scroll.latency.p95", "frames.dropped", "cpu.work", "gpu.process.3d"],
async run({ page, phase }) {
await phase("down", () => scroll(page, 6_000))
await phase("up", () => scroll(page, -6_000))
},
},
// A search typed into History: each key searches all 10,000 entries.
"history-search": {
expect: { heading: "History" },
primary: "ui.cpu",
metrics: ui,
run: ({ page }) => page.type("history-search", "cache key", { delay: 120 }),
async reset({ page }) {
await page.press("Control+a")
await page.press("Backspace")
await page.idle()
},
},
// The speech model picker: open it, its list of every model, back to the
// comparison, and close. Choosing a model would download or load one,
// which is the network's and the model's cost, not the window's.
"model-picker": {
expect: { heading: "General" },
primary: "ui.cpu",
metrics: ui,
async run({ page }) {
// The panel scales in and springs to each view's height, so its
// header buttons move until it rests; a click before then misses
// them (Back did on macOS).
await page.click("transcription-control", { until: "transcription-picker" })
await page.idle()
await page.click("more-models", { until: "all-view" })
await page.idle()
await page.click("picker-back", { until: "compare-view" })
await page.idle()
await page.click("close-picker", { until: "transcription-control" })
},
},
},
})