|
| 1 | +// Main-thread work on the site's pages and interactions, for strobe (https://github.com/Hona/strobe). |
| 2 | +// Each variant is the production build (script/build.ts) served in workerd by perf/serve.ts. |
| 3 | +// |
| 4 | +// strobe bench services/site/perf/site.bench.ts --base origin/dev --head . --headless |
| 5 | +// |
| 6 | +// Loads are returning visits: each run navigates from about:blank with the HTTP cache warm, so they |
| 7 | +// measure parsing, running and hydrating the page's code, not the network. Interactions start from a |
| 8 | +// fresh load of the home page, so each run is the first ⌘K, hover or click after a load. |
| 9 | +import { bench, url, web, type Context, type RunCase } from "@hona/strobe" |
| 10 | + |
| 11 | +const desktop = { width: 1440, height: 900 } |
| 12 | +const phone = { width: 390, height: 844 } |
| 13 | +const card = '[data-component="products"][data-layout="carousel"] [data-component="product-card"] [data-slot="media"]' |
| 14 | + |
| 15 | +// Absolute: page.goto resolves a relative path against about:blank after the reset. |
| 16 | +const load = (path: string): RunCase<unknown> => ({ |
| 17 | + primary: "main.work", |
| 18 | + run: async (ctx) => { |
| 19 | + await ctx.page.goto(new URL(path, ctx.url).href) |
| 20 | + await ctx.page.idle() |
| 21 | + }, |
| 22 | + reset: (ctx) => ctx.page.goto("about:blank"), |
| 23 | +}) |
| 24 | + |
| 25 | +const reload = async (ctx: Context<unknown>) => { |
| 26 | + await ctx.page.goto(new URL("/", ctx.url).href) |
| 27 | + await ctx.page.idle() |
| 28 | +} |
| 29 | + |
| 30 | +export default bench({ |
| 31 | + targets: { |
| 32 | + desktop: web({ url: "/", viewport: desktop }), |
| 33 | + phone: web({ url: "/", viewport: phone, scale: 3 }), |
| 34 | + // The live site, for reference only: `--target production --blocks 5 --head .` (nothing to build). |
| 35 | + production: url("https://opencode.ai/", { viewport: desktop }), |
| 36 | + }, |
| 37 | + async setup({ page }) { |
| 38 | + await page.idle() |
| 39 | + }, |
| 40 | + cases: { |
| 41 | + "load-home": load("/"), |
| 42 | + "load-product": { ...load("/product"), targets: ["desktop", "production"] }, |
| 43 | + "load-desktop": { ...load("/desktop"), targets: ["desktop", "production"] }, |
| 44 | + "load-docs": { ...load("/docs/"), targets: ["desktop", "production"] }, |
| 45 | + "scroll-home": { |
| 46 | + primary: "main.work", |
| 47 | + targets: ["desktop", "production"], |
| 48 | + run: ({ page }) => page.scroll("main", { by: 12000, speed: 6000 }), |
| 49 | + reset: reload, |
| 50 | + }, |
| 51 | + search: { |
| 52 | + primary: "main.work", |
| 53 | + targets: ["desktop", "production"], |
| 54 | + run: async ({ page }) => { |
| 55 | + await page.press("ControlOrMeta+k", { until: '[data-component="site-search"] [role="dialog"]' }) |
| 56 | + await page.idle() |
| 57 | + }, |
| 58 | + reset: reload, |
| 59 | + }, |
| 60 | + "card-hover": { |
| 61 | + primary: "main.work", |
| 62 | + targets: ["desktop", "production"], |
| 63 | + run: async ({ page }) => { |
| 64 | + await page.hover(card) |
| 65 | + await page.idle() |
| 66 | + }, |
| 67 | + reset: async (ctx) => { |
| 68 | + await ctx.page.move(1, 1) |
| 69 | + await reload(ctx) |
| 70 | + }, |
| 71 | + }, |
| 72 | + "card-open": { |
| 73 | + primary: "main.work", |
| 74 | + run: async ({ page }) => { |
| 75 | + await page.click(card, { until: '[data-component="product-hero"]' }) |
| 76 | + await page.idle() |
| 77 | + }, |
| 78 | + reset: reload, |
| 79 | + }, |
| 80 | + }, |
| 81 | +}) |
0 commit comments