hex/site/perf/hex.bench.ts

54 lines
2.1 KiB
TypeScript

import { bench, web } from "@hona/strobe"
// The landing page as a desktop visitor sees it: the prerendered page, then the show engine (WebGPU) takes over the
// head once the browser is idle. data-live goes on the page once the engine has drawn the head.
const url = "/hex/"
const live = "main[data-live]"
export default bench({
targets: {
web: web({
viewport: { width: 1440, height: 900 },
url,
// Every block must be on the landing page, not an error page or another route.
expect: { title: "Hex: voice dictation", url: "/hex/" },
prepare: ({ addInitScript }) =>
addInitScript(() => {
// The show's own frames: one swapchain texture per drawn frame, as count.frame.
if (typeof GPUCanvasContext === "undefined") return
const take = GPUCanvasContext.prototype.getCurrentTexture
GPUCanvasContext.prototype.getCurrentTexture = function () {
;(globalThis as { __strobeCount?: (name: string) => void }).__strobeCount?.("frame")
return take.call(this)
}
}),
}),
},
cases: {
// Elapsed time from navigation until the engine draws the head. A headless check needs a lit display.
"load to live head": {
primary: "run.duration",
metrics: ["main.work", "gpu.compile"],
run: ({ page }) => page.goto(url, { until: live }),
},
// The idle head breathing before anyone presses the key.
"idle head 8 s": {
primary: "main.work",
metrics: ["main.busy", "main.gc", "count.frame", "cpu.app.total", "gpu.process.3d", "frames.dropped.pct", "canvas.frames", "canvas.interval.p95"],
run: ({ page }) => page.wait(8000),
},
// Press the option key: the first 20 s of the show (calm, the first OpenCode prompts).
"show opening 20 s": {
primary: "main.work",
metrics: ["main.busy", "main.gc", "count.frame", "cpu.app.total", "gpu.process.3d"],
run: async ({ page }) => {
await page.click(".keycap")
await page.wait(20_000)
},
reset: ({ page }) => page.goto(url, { until: live }),
},
},
async setup({ page }) {
await page.waitFor(live, { timeout: 30_000 })
},
})