Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions services/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@babel/core": "7.29.7",
"@cloudflare/build-output-utils": "0.8.5",
"@cloudflare/config": "0.23.0",
"@hona/strobe": "catalog:",
"@mdx-js/mdx": "3.1.1",
"@types/babel__core": "7.20.5",
"@types/bun": "catalog:",
Expand Down
1 change: 1 addition & 0 deletions services/site/perf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github-snapshot.json
57 changes: 57 additions & 0 deletions services/site/perf/serve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Serves the production build that script/build.ts wrote (.cloudflare/output) in workerd through
// Miniflare, the runtime check-worker-start.ts uses, for strobe benches (strobe.json `serve`). Every
// outbound fetch gets a 503, as in check-worker-start.ts, so both sides of a bench render the
// build-time GitHub snapshot and no live data.
//
// bun perf/serve.ts --port 4300
import path from "node:path"
import { parseArgs } from "node:util"
import { readBuildOutput } from "@cloudflare/build-output-utils"
import { Miniflare, Response } from "miniflare"

const args = parseArgs({ options: { port: { type: "string", default: "4300" } } })
const root = path.resolve(import.meta.dir, "..")
const worker = (await readBuildOutput(root)).workers.default
const config = worker.config
if (!worker.bundleDir || !config.manifest) throw new Error("perf/serve: the Build Output has no Worker bundle")
const bundle = worker.bundleDir
const modules = Object.fromEntries(
await Promise.all(
Object.entries(config.manifest.modules).map(async ([name, module]) => {
const file = Bun.file(path.join(bundle, name))
const contents = module.type === "esm" || module.type === "cjs" ? await file.text() : await file.bytes()
return [name, { type: module.type, contents }] as const
}),
),
)
const env = Object.fromEntries(
Object.entries(config.env ?? {}).map(([name, binding]) => {
if (binding.type === "text") return [name, { type: "text" as const, value: binding.value }]
if (binding.type === "assets") return [name, { type: "assets" as const }]
throw new Error(`perf/serve: the ${binding.type} binding ${name} is not emulated`)
}),
)

const miniflare = new Miniflare({
cf: false,
host: "127.0.0.1",
port: Number(args.values.port),
workers: [
{
config: {
name: config.name,
compatibilityDate: config.compatibilityDate,
compatibilityFlags: config.compatibilityFlags,
triggers: [{ type: "fetch", pattern: "*/*" }],
env,
manifest: { mainModule: config.manifest.mainModule, modules },
...(worker.assetsDir ? { assets: { ...config.assets, directory: worker.assetsDir } } : {}),
},
dev: {
outboundService: { type: "fetcher", handler: () => new Response("offline", { status: 503 }) },
},
},
],
})
console.log(`perf/serve: ${config.name} at ${await miniflare.ready}`)
for (const signal of ["SIGINT", "SIGTERM"] as const) process.on(signal, () => void miniflare.dispose().finally(() => process.exit(0)))
81 changes: 81 additions & 0 deletions services/site/perf/site.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Main-thread work on the site's pages and interactions, for strobe (https://github.com/Hona/strobe).
// Each variant is the production build (script/build.ts) served in workerd by perf/serve.ts.
//
// strobe bench services/site/perf/site.bench.ts --base origin/dev --head . --headless
//
// Loads are returning visits: each run navigates from about:blank with the HTTP cache warm, so they
// measure parsing, running and hydrating the page's code, not the network. Interactions start from a
// fresh load of the home page, so each run is the first ⌘K, hover or click after a load.
import { bench, url, web, type Context, type RunCase } from "@hona/strobe"

const desktop = { width: 1440, height: 900 }
const phone = { width: 390, height: 844 }
const card = '[data-component="products"][data-layout="carousel"] [data-component="product-card"] [data-slot="media"]'

// Absolute: page.goto resolves a relative path against about:blank after the reset.
const load = (path: string): RunCase<unknown> => ({
primary: "main.work",
run: async (ctx) => {
await ctx.page.goto(new URL(path, ctx.url).href)
await ctx.page.idle()
},
reset: (ctx) => ctx.page.goto("about:blank"),
})

const reload = async (ctx: Context<unknown>) => {
await ctx.page.goto(new URL("/", ctx.url).href)
await ctx.page.idle()
}

export default bench({
targets: {
desktop: web({ url: "/", viewport: desktop }),
phone: web({ url: "/", viewport: phone, scale: 3 }),
// The live site, for reference only: `--target production --blocks 5 --head .` (nothing to build).
production: url("https://opencode.ai/", { viewport: desktop }),
},
async setup({ page }) {
await page.idle()
},
cases: {
"load-home": load("/"),
"load-product": { ...load("/product"), targets: ["desktop", "production"] },
"load-desktop": { ...load("/desktop"), targets: ["desktop", "production"] },
"load-docs": { ...load("/docs/"), targets: ["desktop", "production"] },
"scroll-home": {
primary: "main.work",
targets: ["desktop", "production"],
run: ({ page }) => page.scroll("main", { by: 12000, speed: 6000 }),
reset: reload,
},
search: {
primary: "main.work",
targets: ["desktop", "production"],
run: async ({ page }) => {
await page.press("ControlOrMeta+k", { until: '[data-component="site-search"] [role="dialog"]' })
await page.idle()
},
reset: reload,
},
"card-hover": {
primary: "main.work",
targets: ["desktop", "production"],
run: async ({ page }) => {
await page.hover(card)
await page.idle()
},
reset: async (ctx) => {
await ctx.page.move(1, 1)
await reload(ctx)
},
},
"card-open": {
primary: "main.work",
run: async ({ page }) => {
await page.click(card, { until: '[data-component="product-hero"]' })
await page.idle()
},
reset: reload,
},
},
})
11 changes: 5 additions & 6 deletions services/site/src/component/site/console-field.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createEffect, onCleanup, onMount } from "solid-js"
import { createEffect, on, onCleanup, onMount } from "solid-js"

// The Console landing backdrop (dev.opencode.ai/console, preset "vertical" with dots): 2px dots
// where columns cross rows. Gaps are 24px at the centre and tighten to 8px at the edges
Expand Down Expand Up @@ -38,11 +38,10 @@ export function ConsoleField(props: { dot?: number }) {
element.style.setProperty("--console-dots", `url(${canvas.toDataURL()})`)
element.dataset.ready = ""
}
// Redraw when the dot size changes (switching between Console options).
createEffect(() => {
dot()
draw()
})
// Redraw when the dot size changes (switching between Console options). The first draw is the
// resize observer's first callback, after layout and before the frame paints, so mounting neither
// forces a layout nor draws and encodes the mask twice.
createEffect(on(dot, draw, { defer: true }))
const resize = new ResizeObserver(draw)
resize.observe(element)

Expand Down
11 changes: 9 additions & 2 deletions services/site/src/component/site/site-banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,16 @@ export function SiteBanner() {
setDismissed(localStorage.getItem(dismissKey) ?? undefined)
const host = banner?.parentElement
const link = banner?.querySelector("a")
// Reads come before the write, and an unchanged value isn't written again: --banner-scroll sits on
// the page's root, so each write restyles the whole page, and a read after it forced that at once.
// Unset reads as 0px (site-banner.css's fallback), so a page loaded at the top writes nothing.
let offset = "0px"
const scroll = () => {
host?.style.setProperty("--banner-scroll", `${Math.min(window.scrollY, 200)}px`)
setOnTop(window.scrollY < (link?.offsetHeight ?? 0))
const y = window.scrollY
const top = y < (link?.offsetHeight ?? 0)
const next = `${Math.min(y, 200)}px`
if (next !== offset) host?.style.setProperty("--banner-scroll", (offset = next))
setOnTop(top)
}
const paint = () => setBlue(link ? getComputedStyle(link).backgroundColor : undefined)
// The blue changes with the theme (the host's data-theme, or the system's when it follows it)
Expand Down
17 changes: 17 additions & 0 deletions services/site/strobe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "./node_modules/@hona/strobe/schema/strobe.v1.json",
"build": {
// A pinned GitHub snapshot (perf/github-snapshot.json, when present) and a token GitHub refuses
// keep every build's star counts and release list the same, so base and head render one page.
"command": "bun install --frozen-lockfile && (test ! -f perf/github-snapshot.json || cp perf/github-snapshot.json src/lib/github-snapshot.json) && bun script/build.ts --mode production",
"cwd": "services/site",
"output": "services/site/.cloudflare/output",
"env": { "GITHUB_TOKEN": "strobe-pinned-snapshot" },
},
"serve": {
"command": "bun perf/serve.ts --port {port}",
"cwd": "services/site",
"ready": "http://127.0.0.1:{port}/",
},
"harness": ["services/site/perf", "services/site/vite.config.ts"],
}
3 changes: 3 additions & 0 deletions services/site/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ export default defineConfig({
// Oxc, Vite 8's own minifier. "esbuild" here left the bundles unminified: Vite only adds its
// esbuild minifier when the top-level build.minify asks for it, and that stays off for the Worker.
minify: "oxc",
// strobe builds with STROBE_SOURCEMAP=hidden: maps beside the scripts without a
// sourceMappingURL comment, so the scripts stay byte for byte and profiles name source lines.
sourcemap: process.env.STROBE_SOURCEMAP === "hidden" ? "hidden" : undefined,
},
},
},
Expand Down
Loading