@ogygia/cli
Perf budgets
`ogygia perf` renders a list of pages under the SSR profiler on a running server, compares the numbers with a baseline under a budget, writes a PR comment and fails CI when a page got slower or heavier. `ogygia bisect` then finds the commit that did it.
On this page
A page rarely gets slow in one big change. It gets a few milliseconds slower in each of many pull requests, and nobody notices until it’s twice as slow. ogygia perf checks every pull request: it renders your pages under the SSR profiler, compares the numbers with the same pages on your main branch, and fails the job when a page grew past the budget you set. When a slowdown got in anyway, ogygia bisect finds the commit that caused it.
npx ogygia perf --url http://127.0.0.1:4173 --pages /,/pricing \
--baseline perf/baseline.json --budget perf/budget.json --md perf/comment.mdRequirements
perf measures a server that’s already running, so your CI job builds the app, starts it, and then runs the command. That server has to list the profiler: devtools({ profiler: true }) from @ogygia/devtools/vite beside ogygia().
With the recommended setup, devtools() sits behind a mode !== 'production' check, so a plain vite build leaves the profiler out. Build in another mode for the job, such as vite build --mode staging.
A build turns the profiler on only with a secret of 16 bytes or more. Start the server with OGYGIA_PROFILER_SECRET in its environment, and give perf the same value, with --key or the same variable. Without a secret every profiler route answers 404, and perf stops with “the profiler answered 404” and exit 2, with no hint about the secret (#2314, item 16). The same goes for the app bisect starts with --start: it inherits your environment, so export OGYGIA_PROFILER_SECRET first, or set it in the --start command as the example does. A dev server needs no secret, but its numbers only point the way, so measure a build.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { devtools } from '@ogygia/devtools/vite';
import { defineConfig } from 'vite';
export default defineConfig(({ mode }) => ({
plugins: [
ogygia(),
...(mode !== 'production'
? [devtools({ profiler: true })]
: []),
sveltekit()
]
}));CI workflow
Run perf twice: once on your main branch with --out, and once on each pull request against that snapshot. perf doesn’t wait for the server, so wait until it accepts a connection before you run it: a request that arrives first fails with “the profiler did not answer” and exit 2. The curl below tries once a second for a minute, then fails the job, so a server that crashes at boot doesn’t hang it. ${GITHUB_SHA::7} labels the run with the short commit. On main:
Keep perf-baseline.json where the pull request’s job can fetch it, such as a CI artifact or cache entry saved by the main-branch job. A missing baseline isn’t an error: every page is judged as new. On the pull request:
It profiles one page at a time, with --runs renders each (5 by default, 1 to 50), through POST <url><base>/page?p=<page>&runs=<n>&format=json. It prints a line per page as it goes, then one verdict line per page and the failures. With --md, the markdown comment is ready to post on the pull request. Use five runs or more on a shared CI machine: the median of five holds within a few percent, and a single render doesn’t.
Pages come from --pages, comma-separated, and from --pages-file, a JSON array or { "pages": [...] }. Each must be a path that starts with /.
pnpm vite build --mode staging
OGYGIA_PROFILER_SECRET="$OGYGIA_PROFILER_SECRET" node build &
curl --retry 60 --retry-connrefused --retry-delay 1 -s -o /dev/null http://127.0.0.1:3000
npx ogygia perf --url http://127.0.0.1:3000 --pages /,/products,/account --runs 5 \
--key "$OGYGIA_PROFILER_SECRET" --out perf-baseline.json --label "${GITHUB_SHA::7}"pnpm vite build --mode staging
OGYGIA_PROFILER_SECRET="$OGYGIA_PROFILER_SECRET" node build &
curl --retry 60 --retry-connrefused --retry-delay 1 -s -o /dev/null http://127.0.0.1:3000
npx ogygia perf --url http://127.0.0.1:3000 --pages /,/products,/account --runs 5 \
--key "$OGYGIA_PROFILER_SECRET" --baseline perf-baseline.json --budget perf-budget.json \
--out perf-snapshot.json --md perf-comment.md --label "${GITHUB_SHA::7}"Snapshot
--out writes what was measured as JSON. It’s both the result of this run and the baseline of the next.
| Field | Meaning |
|---|---|
render_p50, runs | The median render and every run, in ms. |
busy_ms, wait_ms | Time the CPU was busy, and time spent waiting on calls. |
cold_extra_ms | How much longer the first, cold render took than the median. |
seed_kb, props_kb | The page seed and the islands’ props, in KB. |
islands_js_kb, islands | The JavaScript the page’s islands load in a build, each module counted once, and the island count. |
components, functions | The 15 components and 15 functions with the most self time. |
paths | The five paths to fix: their owner and what they cost. |
warnings | The finding codes at warn level. |
phases | Time by phase of the render. |
{
"version": 1,
"at": 1764547200000,
"node": "v24.11.1",
"label": "3f2c1ab",
"pages": [
{
"page": "/products",
"render_p50": 41.2,
"runs": [40.8, 41.2, 43.0, 41.0, 41.9],
"busy_ms": 28.4,
"wait_ms": 9.1,
"cold_extra_ms": 12.5,
"seed_kb": 3.2,
"props_kb": 1.4,
"islands_js_kb": 18.7,
"islands": 4,
"components": [{ "name": "ProductGrid", "self_ms": 6.1, "total_ms": 19.8 }],
"functions": [{ "name": "format", "file": "src/lib/price.ts", "self_ms": 2.3 }],
"paths": [{ "owner": "ProductGrid", "ms": 7.4, "fns": 3 }],
"warnings": ["seed-whole"],
"phases": { "load": 9.1, "render": 30.2 }
}
]
}Budget file
--budget names a JSON file. Every key is optional and falls back to the default below. pages sets any of them for one page, and wins over the top level.
| Key | Default | Fails when |
|---|---|---|
render_pct, render_floor_ms | 8, 5 | The median render grew by more than this percent of the baseline and by more than this many ms. |
render_max_ms | none | The median render is over this many ms. |
busy_pct | 15 | CPU busy grew by more than this percent, and by more than render_floor_ms. |
component_pct | 25 | One component’s self time grew by more than this percent, and by more than 2 ms. A component new since the baseline never fails. |
seed_kb, seed_max_kb | 20, none | The seed grew by more than this many KB, or is over the cap. |
props_kb | 30 | The islands’ props grew by more than this many KB. |
islands_js_kb, islands_js_max_kb | 30, none | The islands’ JavaScript grew by more than this many KB, or is over the cap. |
cold_extra_ms | 100 | The cold render’s extra time grew by more than this many ms. |
fail_on | none | One of these finding codes appears that the baseline didn’t have, or, for a page with no baseline, is there at all. Only codes at warn level are kept, so info codes never fail. |
The floor keeps a fast page from failing on noise: a 4 ms page that renders in 5 ms grew 25 percent, but by only 1 ms. Waiting on calls and the island count are shown but never judged.
{
"render_pct": 8,
"render_floor_ms": 5,
"seed_max_kb": 300,
"islands_js_max_kb": 250,
"fail_on": ["seed-whole", "hydration-mismatch"],
"pages": { "/": { "render_max_ms": 120 } }
}Verdict
Each page is judged against the same page in the baseline. A page the baseline doesn’t have is new, and is judged by the caps alone (the _max_ keys and fail_on). A page in the baseline that this run didn’t measure is listed as not measured, and fails nothing. Without --baseline, or when its file doesn’t exist yet, every page is new, so the first run on main can’t fail on growth.
The command exits with 0 when every page is within budget, 1 when one isn’t, and 2 when the arguments are incomplete or a page couldn’t be measured: the profiler didn’t answer within two minutes, answered an error, or answered something that isn’t its JSON. A profiler busy with another recording answers 409, and the message says so. A missing or wrong key is less clear: the profiler redirects the request to its login page, perf follows the redirect, and the message says the answer wasn’t JSON and asks whether the path is right. Check --key first when you see it (#2314, item 6). A build with no secret at all answers 404 (Requirements). --no-fail turns a failed budget into exit 0, for a job that should only comment.
PR comment
--md writes the verdict as markdown. It leads with the outcome and lists every failure. Then each page gets a table of its numbers (the baseline, this run, the change and the budget), its three biggest movers among components, functions and paths with their files, and the findings that appeared or went away. --label goes in the title.
### Performance (3f2c1ab): ❌ 1 budget failure
- ❌ /products: render grew 6.3 ms (8% allowed)
#### ❌ `/products`
| metric | base | PR | Δ | budget |
|---|---:|---:|---:|---|
| render (median) | 34.9 ms | 41.2 ms | +6.3 ms (+18%) ❌ | +8% (≥ 5 ms) |
| CPU busy | 26.0 ms | 28.4 ms | +2.4 ms (+9%) | +15% |First bad commit
When a page got slower somewhere in the last N commits, ogygia bisect finds where. Run it in your repository with a commit where the page was fast and one where it’s slow:
For each commit it checks, it adds a git worktree in a temporary folder, runs --build there with CI=1 set, starts the app with --start, profiles --page with --runs renders (3 by default), stops the app and removes the worktree. Your own checkout is never touched.
It measures the two ends first and sets a bar between their medians: good + (bad − good) × margin, halfway with the default --margin 0.5. A commit whose median is over the bar counts as bad. Then it searches the commits between the two refs, halving the range each time, so noise below the bar can’t send it the wrong way. After the two ends, ten commits take at most four more builds, and a hundred at most seven.
A commit that fails to build, to start or to measure is skipped, and the search tries the commit nearest the middle instead. At the end it names the first bad commit with its subject, the last good one, the bar, and how many steps and skips it took. It exits with 0 when it named a commit, 1 when no commit crossed the bar (the slowdown isn’t in the range, or it was noise), and 2 when a required flag is missing, the range is empty, or either end couldn’t be measured.
Bisect servers
Each commit’s app takes the same port, so bisect makes sure the server it measures is the one it started:
- Before it starts a commit’s app, it waits for the port in
--urlto be free. A port still held when--readyruns out skips the commit withcli_server_port_busy: another process is on it, such as a server left running in another terminal. - It polls
--urlevery 200 ms until it answers with a status under 500, for up to--readyms (60 seconds by default). An app that exits first is skipped withcli_server_exited_early, and one that never answers is stopped and skipped withcli_server_not_ready. Both messages end with the app’s last 40 lines of output. - The app runs in its own process group. Stopping it sends
SIGTERMto the whole group, andSIGKILL10 seconds later, so a server behind a wrapper such aspnpm startis stopped too. The next commit starts only once the group is gone.
A build gets --build-timeout ms (15 minutes by default) before it counts as failed.
npx ogygia bisect --good v1.4.0 --bad HEAD --page /products \
--build "pnpm install --frozen-lockfile && pnpm vite build --mode staging" \
--start "OGYGIA_PROFILER_SECRET=$OGYGIA_PROFILER_SECRET node build" --url http://127.0.0.1:3000 --key "$OGYGIA_PROFILER_SECRET" --runs 3Limits
- A
--budgetor--pages-filepath that doesn’t exist is read as empty, with nothing said: the default budget applies, or no pages are added. Check the paths in your workflow (#2314, item 5). - A
--runsof0falls back to the default rather than meaning one (#2314, item 7). - The comparison is only as steady as the machine. Measure the baseline and the pull request on the same kind of runner, with the same
--runs.