Skip to content

@ogygia/devtools · Profiler

Render timeline

Why one render took as long as it did. The split between computing and waiting, the critical path and its phases, every load function on one clock, who waited for whom, the network waterfall, waits HTTP never sees, other requests on the same instance, cold starts and runs that drift.

On this page

Every table in a report adds up the whole recording. The timeline does the opposite: it takes one render and walks it from its first millisecond to its last, so you can see which stretch was CPU, which was a wait, and what each wait was for. For a page profile, that’s one of its timed runs.

The most common fix it points to is a chain of waits that didn’t need to be a chain:

import {
  getProduct,
  getReviews,
  getStock
} from '$lib/server/api';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ params }) => {
  // slow: about the sum of all three
  // const product = await getProduct(params.id);
  // const reviews = await getReviews(params.id);
  // const stock = await getStock(params.id);

  // fast: about the slowest one
  const [product, reviews, stock] =  await Promise.all([
    getProduct(params.id),
    getReviews(params.id),
    getStock(params.id)
  ]); 
  return { product, reviews, stock };
};

Time breakdown

One bar for the whole window, split by what the CPU was doing: your code, packages, Svelte, Kit, ogygia, Node, GC, and idle / waiting. Read it first, because it tells you which kind of problem you have.

  • When the biggest segment is your code, it’s a compute problem: the slow patterns, the treemap and the component table are next.
  • When the biggest segment is idle / waiting, the server was blocked on I/O and a CPU profiler would have found nothing. Go to the network and waiting by function.

The report’s verdict says the same in one word: waiting when more than half the window was idle, compute-bound when the CPU was busy more than 60% of it, and mixed otherwise.

Critical path

A page or request profile opens with one render walked end to end. Every stretch is one of three things:

  • running: the CPU ran something, coloured by the component or function that owned it;
  • waiting: on outbound calls or I/O, drawn blue for HTTP and amber for timers, files and sockets, with several bars at once marking a parallel group;
  • a gap: time nothing recorded, such as a database driver on its own socket pool, a worker, or a promise chain.

The numbered steps under the bar are the critical path in order, and the biggest is the one to fix. A gap says what was pending during it, when anything was: nothing recorded — pending: GET /api/x (+2). The profiler can’t see the CPU work of those milliseconds, but it can see which calls were still open, and that’s usually the answer. To name it properly, add a span. When gaps are more than 30% of the render and over 20 ms, unseen-wait says so.

Two more readings come from the same walk:

  • Phases split the render by where in the request the time went: hooks, load functions, component render, ogygia’s transform, and Kit’s routing and response. A wait is charged to the phase whose code ran just before it, so “load: 2 ms CPU + 210 ms waiting” says straight away that the page is bound by data, not rendering. A handle you import into hooks.server.ts from another file counts as hooks too, including its work after await resolve(). Library work that carries on after an await with none of your code under it is charged to whichever phase last called into that library. The phases note gives the split.
  • Awaits in a row: two or more calls that ran one after another with nothing between them, flagged with what starting them together would save (the sum minus the longest). The profiler can’t know whether they’re independent, but you can. sequential-awaits warns when the saving is 5 ms or more and 5% of the render.

Line-level breakdown

One render’s time as a tree that adds up at every level. The top level is the part of the request (hooks, load functions, component render and so on). Under the loads comes each load file, then who held the time (your function, a library, or a call it waited on), and finally the line. Small rows fold into an N more row you can open, so nothing is dropped, and a fold never hides more than a tenth of its level.

  • Your function splits by what its samples ran inside it: its own lines and the lines of the arrow functions and helpers under it, from the call stacks.
  • A library splits into the lines of yours that call it. Called from a single line, it splits into its own functions instead (”some-lib → getNamedItem 23 ms, computeMode 14 ms”).
  • A call you waited on splits into the line that made it and, through a helper, the line that called the helper. Waits that overlapped share the stretch evenly.
  • garbage collection splits into the lines that made the garbage, weighted by the pauses each caused.
  • nothing recorded names what was pending, with the line that queued it.

A row can carry these labels:

  • alone, or N ms alone, on a wait: how long nothing else was in flight, the least a faster answer would save. always beside other calls means it saves nothing unless the others get faster too.
  • each call: X ms their side (…), Y ms network, Z ms body: the call’s own clock. “Their side” is the service’s own Server-Timing (nested entries not counted twice).
  • → keys: the page.data keys the row’s lines feed, read from your load’s source. A key nothing reads is struck through, and nothing reads it means all of the row’s time bought nothing (Unused data).
  • N renders on a component: how many times it rendered in one render of the page.
  • a–b ms over renders: the row’s lowest and highest across the profiled renders. A difference smaller than that range is noise.
  • N ms cold: what the row took in the first, cold render, when it stands out.
  • tags: the slow patterns found on the row’s lines.

In the JSON it’s drill.

Load waterfalls

Under the timeline, a page profile draws one lane for each Kit load function that ran (+layout.server.ts, +page.server.ts, a universal +page.ts), each from its first moment on the CPU or waiting to its last, on the render’s clock. The chip says server or universal, and await parent() when Kit’s parent() ran under that load. A wait inside a span() counts toward its lane.

Kit runs a page’s load and its layouts’ loads together. When the page lane starts only where the layout lane ends, they ran one after the other, and parent-chain says so with the most that overlapping them would save. The usual cause is an await parent() before the page’s own fetches. Start the fetches first and await parent() after:

A load that calls the site’s own API through Kit’s fetch never reaches the network, because Kit answers it in-process. The profiler wraps that fetch while it records, so those calls show like any other, with their caller and their Server-Timing.

A universal load that waits 5 ms or more gets universal-load, because on a page with Kit’s client router that code runs again in the browser on every navigation, and its data has to be serializable. If it only needs the server, make it a +page.server.ts.

import { getOrders } from '$lib/server/api';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ parent }) => {
  const orders = getOrders(); // started before the wait
  const { user } = await parent();
  return { user, orders: await orders };
};

Causality graph

Awaits draws the render’s outbound calls and spans as boxes on lanes, with an arrow from each call to the one that started right after it ended (within 5 ms, with nothing else in flight). A chain of arrows is a chain of awaits: the second call couldn’t start before the first answered, because it needs the answer or because the code says await where it could say Promise.all. Each arrow carries the gap between the two calls and, with source maps, the await that started the second.

The list under the drawing is the same graph as text, longest chain first. Many arrows on one lane is what a serial page looks like; the same calls spread over several lanes with no arrows is a parallel one.

What if

Under the causality graph, What if… lets you change a call and see the render under a model of it: parallel starts the call together with the call it waited for, cache makes it instant, and remove takes it out. The wall time is recomputed from the graph, with the longest remaining chain spelled out. The CPU between calls stays as recorded; only the waits move. It’s a model and says so, but “those eight product calls together: 412 ms becomes 260” is a plan you can test before touching code.

Raw samples

Slice it shows the data before any table added it up: every CPU sample of the render, each with its stack, drawn as a density strip (grey for any CPU, green for a component’s). Drag a range and the tables under it answer for that stretch alone: what ran itself (self), what was on the stack over it (owners), and which components were involved. Hover an instant to list its stack, outermost frame first. Yellow marks are collections.

This matters because a function that’s 12% of the render may be 90% of the 80 ms stretch you care about. The index is limited to the window and folded (consecutive samples of one leaf become one entry), so it costs a few hundred kilobytes rather than the megabytes of the raw profile; past 20,000 entries it’s stride-sampled with the lengths kept. In the JSON it’s stacks: a frame table with parent links and three parallel arrays (t_ms, d_ms, leaf).

Render sequence

The same render as a list you can walk: this component ran for this long, then the server waited for that call, then the next component ran. Each step carries its end time, the CPU used so far, the leaf that burned time inside it, the calls in flight during a wait, the span it sat in, and the stack at its midpoint. Step with a slider or the arrow keys; the longest steps are jump targets. Consecutive steps with one owner merge, and past 80 steps the smallest fold into a neighbour, which says how many it absorbed. In the JSON it’s steps.

Network

Every outbound fetch and http/https call the render made, tied to the line that made it, on a real timeline. Expand a call to see its payload as formatted JSON (rendered lazily and off the main thread, so a multi-MB body opens without freezing the page), its wire and decoded sizes, its encoding, and its call path: the function that made the call and the functions that called it (fetchStock ← load). The waterfall shows one representative render, not the same calls once per run.

The classic slow shape is easy to spot: several calls stacked one after the other with no overlap. A call with a large “wait” but a small “body” points to a slow upstream; a large “body” points to a slow or oversized response.

The findings that read the network: n-plus-one (the same endpoint once per item, folded to /products/:id), sequential-network (back-to-back calls for over half the window while the CPU was under 60% busy), slow-upstream (one host over 20% of the window), network-errors and mostly-waiting.

Upstream Server-Timing

When an upstream answers with a Server-Timing header, the profiler reads it and draws it inside the wait: “GET api/catalog waited 220 ms; their side says db 180 ms, render 20 ms”. The upstream-split finding (on the slowest such call of 20 ms or more) then says how much of the wait is theirs and how much is the network and their framework, so you know who to take it to. Any service can send the header, and a SvelteKit app with this profiler’s serverTiming on already does. Entries that nest (a render 30 holding db 21) aren’t counted twice.

Nested traces

While a recording runs, every outbound call carries an x-og-trace request header. An upstream that also runs this profiler with serverTiming on answers with its own summary of that request in the same header: its time on its own clock, its CPU, its own waits and how many calls, the route it ran, and its biggest calls. The waterfall’s drawer expands the call into that summary, so “this call took 300 ms” becomes “40 ms of it was the upstream’s CPU, 200 ms its own database, 60 ms the network between us”: two services in one report.

Turn serverTiming on only where every client is yours: Public deploys says what the trace exposes.

Waiting by function

The waterfall covers HTTP, but a render also waits on things HTTP never sees: a file read, a setTimeout, a DNS lookup, a raw socket. This table times that I/O with async_hooks and charges each wait to the nearest frame in your code, so a slow readManifest shows up as the function that waited rather than a slice of “idle”. Each row gives the function, its kind of wait (timer, fs, dns or tcp), how many times and the total. When the breakdown is mostly idle and the network looks clean, the missing time is usually here. In the JSON it’s waiting.

Concurrent requests

A Node process has one event loop, so every other request the server answered while the profiled render ran took turns on the same CPU. Those turns sit inside the render’s wall time without a frame of their own. This section names the requests that overlapped the window, how long each was in flight during it, and an upper bound on the CPU each could have taken. The page’s own deferred holes appear too, marked as such. busy-instance warns when something else was in flight for a tenth of the window or more; read the CPU numbers rather than the wall time then, or record on a quiet instance. self-fetch notes a render that called its own server, and holes-in-flight the page’s own holes answered meanwhile. In the JSON it’s contention.

The CPU sampler hears the whole process, so another page’s work lands in the same profile. A sample whose stack runs under another route’s page or layout file belongs to that other request: it’s set aside with everything below it, so the other page’s lines, islands and seed never read as this page’s (other_requests_ms).

Other visitors to the same page run the same lines, so no stack can tell them apart, but the clock can. A render that an outside request for the same path overlapped is left out, as long as at least one ran clean; when fewer than two did, the recording makes more, up to twice the runs asked for. runs-set-aside says how many. When every render was overlapped, nothing is left out, and the finding says how much higher the CPU may read. On Lambda neither happens, because an instance serves one request at a time.

Cold starts

A page profile renders the page once before the measured runs, and profiles that first render on its own as a coarse window. The report shows what it cost beyond a warm render per file: module loading, compiling, and first-call caches. On a serverless host every new instance pays exactly this on its first request, so a “few hundred ms slower first byte on preview deploys” shows up as a table of files. Pass cold=0 to skip it.

cold-start warns when the first render took 1.5× a warm one and 50 ms more, and splits the extra into CPU and waiting. When that render made outbound calls, the waiting is their new connections (DNS, TLS, empty pools), and the advice is to reuse one client. When it made none, the waiting is the first loads of modules and files, and the advice is fewer and smaller server modules on the page’s path.

On AWS Lambda (where Amplify runs SSR) the report also shows the instance’s own start: the time from its process starting to its first request, Node’s share of it, how old the instance was, and how many requests it served before the recording. cold-instance notes it when it’s 100 ms or more.

Per-run variance

In a page profile the components table has a per run column with each component’s time in each render, as min · median · max. A component that takes 90 ms in the first render and 2 ms after points to a cold cache or a lazy import, and the row says cold 1st (component-cold-run). One that jumps in a random run (3× its median and 10 ms more) says varies (component-variance). In neither case is the answer to make the component faster.

Instance aging

When every render takes longer than the one before, slower-each-run says so, with about how many ms each render adds and the first and last run. It needs 4 runs (a cold first run is left out), three quarters of the pairs of runs agreeing, and a rise of at least 3 ms and 5% of the first, so one slow run doesn’t trigger it. When the same report caught memory a render leaves alive, the finding names that as the likely cause and links to Retained memory. On a long-lived server the climb continues until the instance restarts.

Profiler overhead

Every number in a report is what the app would have paid without the profiler. Its own CPU frames (the I/O tracker, the fetch wrapper, its reads) are measured and kept out of busy time, along with the Node work they call. A Node or V8 frame (the inspector’s dispatch, performance.now) counts as the profiler’s when its nearest caller outside Node and V8 is the profiler; the same Node function under your code stays yours. The profiler’s share of each GC pause is removed by its share of the allocations before that pause.

Each run loses exactly what fell inside it, because the start-up scan of compiled code and the final reads sit outside the runs. The header shows what was taken out, and the JSON carries the runs both as reported and as the clock measured them (target.runs, target.runs_measured, summary.overhead). What can’t be seen from inside (the sampler’s own thread and the inspector’s) isn’t taken out, and amounts to a few percent.