@ogygia/devtools · Profiler
SSR profiler
An SSR profiler for SvelteKit that you turn on with one Vite plugin. Open /__profiler, type a path, and it names the components, functions, outbound calls and allocations that made the server render slow, without any timing code of your own.
When a page takes seconds to render on the server, the cause is rarely visible from the outside. It might be a heavy component, a load that awaits three services one after another, a markdown pass, or the garbage collector. A CPU profiler on its own misses the time spent waiting, and a request log on its own misses the time spent computing, so neither tells you the whole story.
The profiler answers one question, why is this server render slow?, by naming the lines responsible. You don’t wrap components or add timing code. Turn it on in vite.config.ts, start the dev server, open /__profiler and profile a path.
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()
]
}));How it works
While a render runs, the profiler watches the whole Node process through the built-in V8 inspector and splits the wall clock into everything that happened during it:
- component SSR and
loadfunctions, down to the line; - outbound
fetchandhttpcalls, tied to the request and the line that made them; - garbage collection, and what each render allocates and keeps;
- time spent waiting rather than computing, and on what.
Svelte compiles each component to a function named after its file, so a CPU sample taken inside a render already knows it is in Cart or ProductGrid. The profiler reads those names straight off the stack, maps each frame back to your source through the build’s source maps, and then reads your source to recognize known slow habits on the costly lines. The result is a report that leads with what to fix and what each fix is worth.
It also hears the browser. When you open a page while logged in to the profiler, a small script reports what your browser measured (vitals, each island’s hydration, layout shifts, the main thread’s CPU), and the report puts the browser and the server on one clock.
Installation
The profiler ships in @ogygia/devtools:
You turn it on in vite.config.ts and nowhere else. List devtools() after ogygia() and before sveltekit(), as above. The mode check is the recommended default: devtools are on in dev and in builds for other modes (vite build --mode staging), and left out of production builds entirely. Keeping the profiler in a production build is an advanced option with caveats; Production explains both. ogygia.handle() mounts the profiler for you, so there’s no hook to add and no route files to write: src/hooks.server.ts stays a plain sequence(...).
devtools({ profiler: true }) also turns on the dock. For the profiler alone, turn the dock off. To change a setting, pass an object in place of true. Configuration lists every option.
The profiler’s own code loads on the first request through a dynamic import, so the plugin costs nothing at boot. If it can’t load (a dev server in the middle of an edit, or a broken install), every request is still answered and the server prints devtools_profiler_mount_failed once. The next request tries again.
pnpm add @ogygia/devtoolsimport { 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({
dock: false,
profiler: { maxReports: 12 }
})
]
: []),
sveltekit()
]
}));Dev and builds
Where the profiler runs decides how open it is and how exact its numbers are:
| Where | Access | Numbers |
|---|---|---|
vite dev | Open at /__profiler, no login, to anyone who can reach the dev server. The x-profile header profiles a request whatever its value. Don’t expose vite dev --host on a network you don’t trust. | Include Vite’s module loading and transforms (the dev-mode note says so). The page’s files aren’t weighed. Good for finding the lines. |
vite build --mode staging + vite preview | Build rules: nobody can log in or record until you set a secret of 16 bytes or more, then /__profiler asks for a login. With no secret it answers a plain 404; a shorter one falls through to your app (Secret). | Real: the code your visitors run, its JS weighed, its source maps read. |
| A deployed build | The same login, on a staging or preview deploy only your team can open. A production build has no profiler with the recommended setup (Production). | Real, on the host’s own hardware. Production covers serverless hosts. |
To profile a build on your own machine, build it in a mode other than production, so the plugin is listed, and start the preview with a secret. Then open http://localhost:4173/__profiler and log in with the same string:
Compare forecasts and timings on a build. Use the dev server to find the lines and check that a fix changed them.
pnpm vite build --mode staging
OGYGIA_PROFILER_SECRET=$(openssl rand -hex 32) pnpm vite previewDev server
vite dev gives the same findings as a build. Vite runs each server module as transformed code built from a string, which hides where the code came from in four ways, and the profiler handles each of them:
- Lines. A profile’s line numbers refer to the transformed code. The maps back to your source live in Vite’s module graph, and the ogygia plugin hands them to the profiler.
- Callers. A stack frame in such code has no file name, only its
sourceURL, which the profiler reads instead. - Call counts. Coverage names such a script
/app/x.tswhile the CPU profile saysfile:///app/x.ts, so the counts are matched by script id. - Memory. The memory sampler leaves such a script unnamed, and the profiler names it from the CPU profile.
Vite’s pre-bundled dependencies (node_modules/.vite/) are filed under the package they belong to, including Svelte’s own runtime, even in a shared chunk named something like dev-Cl0b.js.
Which page.data keys each island reads is normally the build’s answer. On the dev server the plugin runs the same analysis whenever the profiler asks, covering the island’s component, the app modules it imports, and a helper it hands the page to, one level deep. That’s why “ships all page data” and “waits for a late island” work in dev too. The seed the dev server sends is unchanged, and its timings are the dev server’s.
A few things exist only in dev: an opened row shows your source lines with the hot line marked (GET /__profiler/source, which reads only files inside the project). And a few exist only in a build: the page’s weight and score parts that need it, and the standalone HTML download.
Dashboard
/__profiler opens on the dashboard. From top to bottom:
- Profile a page: a path and a number of renders (5 by default). Tick .ogp on a serverless host to get the report back as an encrypted file. Recording covers every way to record.
- In the background: the slow-request trap and always-on sampling when they’re configured, what they caught, and why one stopped.
- Pages over time: each profiled page’s median render and score over its reports, with a link to compare any two.
- Fix once, faster on every page: slow lines that several pages share.
- Reports: the reports this instance holds, each with its biggest fix, plus the ones a store or this browser kept.
- Holes on this server: every deferred hole the server answered, with its cache and render-slot figures.
- Slowest routes: p50 and p95 per route from the always-on request log.
?by=<key>splits it by atag(), though only requests made while a recording ran carry tags. - Recent requests: the request log itself, the last 500 by default.
The sidebar adds Whole site (the site view) and Import .ogp. Reset frees a wedged recording.
Requirements
Recording needs a Node.js server: vite dev, vite preview, adapter-node, or a Node host. It uses node:inspector for the CPU and heap, perf_hooks and process.cpuUsage.
On a runtime that lacks one of those (an edge runtime such as Cloudflare Workers or Deno Deploy), the profiler keeps going without it: every request is still answered and logged, and a recording you ask for is refused with a 501. The server prints devtools_profiler_runtime_unsupported once, naming what’s missing.
On a serverless Node host (AWS Lambda, Amplify, Vercel, Netlify) recording works, but the instance is short-lived. Take the report with you as a file, or give every instance a shared store. Serverless hosts covers both.
In any build, every route stays closed until you set a secret and log in, and the CPU is sampled only while a recording runs (Overhead). Even so, leave devtools out of production builds until #2307 is fixed. Production explains the recommended setup and the advanced option of keeping the profiler in.
Next steps
Recording and setup:
- Recording: profile a page, one request, a window of requests, or the slow request you can’t reproduce.
- Configuration: every option,
Server-Timing, environment variables and overhead. - Production: the secret, the login, serverless hosts, source maps and error codes.
- Report storage: where reports live, stores, exports and share links.
- Scripts and CI: the JSON report, every route,
@ogygia/devtools/report, MCP,ogygia perfandogygia bisect. - Custom spans: name the waits the profiler can’t see, on the server and in the browser.
Reading a report:
- Reports: the layout, the first fixes and the page score.
- Slow patterns: the slow habits found on your lines, and the forecast.
- Render timeline: one render step by step, its waits, and the network.
- CPU: the treemap, components, functions and the flame graph.
- Memory: GC, heap growth, and what a render keeps.
- Page data: who reads which key, the seed, islands and holes.
- Browser metrics: vitals, hydration and third parties on one clock.
- Comparisons: since your last profile, two reports side by side, and the whole site.
- Findings: every finding code, what triggers it and its threshold.