Baselines and regressions

For AI agents: this page is Markdown at https://squiggle.sh/docs/performance/baselines.md. Every docs page is listed at https://squiggle.sh/llms.txt, and all of them are one file at https://squiggle.sh/llms-full.txt.

Save a session as a baseline, compare later sessions with it, and fail a CI build when a number moves too far.

Save a baseline

A baseline is a saved summary of one session: its metrics, timings, startup phases and render counts. Run the flow you want to watch, then save the session it made:

Terminal
squiggle flow checkout                        # run the flow on mainsquiggle perf snapshot --label main           # save that session as "main"

Save again under the same label and comparisons use the newest one. In Studio, press Snapshot as baseline on the Performance screen’s Insights section. It saves the session you are looking at as main, and the panel then compares each session you pick with it: metrics, span kinds, startup and render counts, with a warning when the two ran in different conditions.

The first baseline is automatic

The first time Squiggle runs your app in a project, it watches the app for a few seconds before driving it and saves that session as a baseline named first, with the startup phases. That is the first of squiggle flow, squiggle flows, squiggle up or your agent’s run_flow. It also keeps the recording, .squiggle/recordings/first.sqrec, so the cleanup never removes it. Compare any later session with it:

Terminal
squiggle perf diff --against first

To take it again, delete .squiggle/baselines/first.json and run a flow. If it can’t be recorded, the run goes on and prints a warning, and the next run tries again. A benchmark, and a run with SQUIGGLE_NO_AUTO_UP=1, never take it.

Compare with it

Terminal
squiggle perf diff --against mainperf diff main → mv6rxxns-1  ! flag "thermal" differs: current 1 vs baseline 0metric (p95)         base       cur     deltaEvent-loop lag      41 ms     18 ms    -56.1%Footprint        421.6 MB  523.9 MB    +24.3%span                    base       cur    delta  n base/curScreenTti             2.8 ms   19.2 ms  +586.4%      28 / 4

The diff lists each metric, span and startup phase that moved, with the findings for the new session. The line starting with ! is a warning that the two sessions ran in different conditions, here a warmer Mac. Treat a diff with warnings as a hint, not a verdict.

A baseline remembers the platform it was saved on, and the diff compares it with the newest session on that platform. If your app builds for iOS and macOS, save a baseline for each, and pass --platform macos to perf snapshot to save one from your Mac app. A diff between an iOS session and a macOS baseline is refused: it would measure the platform, not your change. In Studio, the Performance screen’s iOS, macOS and All switch chooses whose sessions you browse. It appears when apps for both platforms are connected, or, with neither connected, when the project has sessions from both.

Fail a build on a regression

Put your limits in a JSON file and pass it with --assert. The diff is printed first, then each limit it breaks, and the command exits 1.

perf-gate.json
{  "maxMetricP95DeltaPct": { "UiFps": 10, "JsHeapBytes": 20 },  "maxSpanP95DeltaPct": { "ScreenTti": 25 },  "maxStartupDeltaPct": 15,  "maxRenderDelta": { "CartRow": 3 },  "failOnDetectors": ["long-task"]}
Terminal
squiggle perf diff --against main --assert perf-gate.json✗ assertion failed: maxSpanP95DeltaPct.ScreenTti: +586.4% > 25%✗ assertion failed: maxStartupDeltaPct (first frame): +32.3% > 15%✗ assertion failed: failOnDetectors: long-task insight "JS thread blocked 484ms — js_long_task"
KeyFails when
maxMetricP95DeltaPctA metric’s 95th percentile moves more than this percentage, either way. Keys are metric names such as UiFps, JsHeapBytes or ProcCpuPct.
maxSpanP95DeltaPctA span kind’s 95th percentile moves more than this percentage. Keys such as ScreenTti, Http or SqliteQuery.
maxStartupDeltaPctAny startup phase moves more than this percentage.
maxRenderDeltaA component renders more times than in the baseline, by more than this.
failOnInsightSeverityAny finding is at or above this severity: warn or error.
failOnDetectorsAny of these detectors reports a finding.

A metric, span or startup move counts in either direction. A number that got better by more than its limit fails too, which is your cue to save a new baseline. Only maxRenderDelta counts one way: more renders. Drag the limit to see how the gate reads a diff:

25%
What movedBaselineNowChange
Event-loop lag (p95)41 ms18 ms-56.1%, over the limit
Footprint (p95)421.6 MB523.9 MB+24.3%, within the limit
ScreenTti spans (p95)2.8 ms19.2 ms+586.4%, over the limit
Startup: first frame412 ms545 ms+32.3%, over the limit
exit1

Event-loop lag got faster and still breaks the limit: the gate checks how far a number moved, in either direction.

perf-gate.json
{  "maxMetricP95DeltaPct": {    "EventLoopLagUs": 25,    "FootprintBytes": 25  },  "maxSpanP95DeltaPct": { "ScreenTti": 25 },  "maxStartupDeltaPct": 25}
Terminal
squiggle perf diff --against main --assert perf-gate.json✗ assertion failed: maxMetricP95DeltaPct.EventLoopLagUs: -56.1% > 25%✗ assertion failed: maxSpanP95DeltaPct.ScreenTti: +586.4% > 25%✗ assertion failed: maxStartupDeltaPct (first frame): +32.3% > 25%

Start with failOnDetectors and add one detector at a time, picking the ones squiggle perf detector-stats shows fire more on failed runs; see Findings. A severity floor gates every detector at once, including noisy ones.

Set a budget per screen

A budget is a limit you write down for a screen before anything is slow. Budgets go in .squiggle/config.jsonc, keyed by each screen’s full route, the name status and the Screen map show. "*" applies to every screen, and a screen’s own entry overrides it one limit at a time. squiggle init writes a starting set.

.squiggle/config.jsonc
"budgets": {  "*": { "frameP95Ms": 16.7, "rendersPerTap": 60, "memoryCeilingMb": 400 },  "checkout": { "frameP95Ms": 12, "startupToInteractiveMs": 800 }}
LimitMeasured as
frameP95MsThe 95th percentile frame time while the screen is shown.
droppedFramesPerInteractionDropped frames in the second after a tap, for the worst tap.
rendersPerTapRenders caused by the heaviest single tap.
startupToInteractiveMsThe screen’s time to interactive. For the first screen, the whole startup.
nativeLaunchMsCold start, on the screen the app opens on: from the process starting to your JavaScript starting. A development build downloads its bundle in this phase.
bundleLoadMsCold start: evaluating your JavaScript bundle, every module your app imports while it starts.
firstRenderMsCold start: from the bundle evaluated to React’s first commit.
firstSettleMsCold start: from the first commit to the first frame where the app holds still.
firstDataMsCold start: from the first commit to the first response to a request the app made while starting. Not measured when the app makes no request while starting.
memoryCeilingMbPeak memory while the screen is shown.
waterfallDepthThe longest chain of requests where each one waited for the last. The report card also fails a screen whose chain got deeper than in its last green run.
longestAnimationMsNot measured. A budget on it always reports “not measured”.
ttfbMsA React web app’s page load, on the screen it opens on: navigation start to the first byte of the page.
fcpMsPage load: navigation start to the first text or image painted.
lcpMsPage load: navigation start to the largest content painted.
inpMsA React web app: the slowest tap, click or key press while the screen is shown, to the next frame drawn.
clsA React web app: how much content moved without the user causing it while the screen is shown (a score, not ms).

An iOS or macOS app measures none of the web limits, and a React web app has no memory footprint of its own, so memoryCeilingMb there reports “not measured”, never 0.

A screen’s network entry sets a time to ready that must hold however slow your server gets, up to a bound: "orders": { "network": { "readyMs": 1500, "latencyUpToMs": 400 } } means the screen’s last response is in within 1.5 s of opening for every request latency from 0 to 400 ms. The report card checks it from the order the screen’s requests ran in during the flow, with every request at 400 ms, which is the slowest case. It passes, or fails with the time that case takes. This is a prediction from one run, not a measurement: to confirm a failure, run the flow with every stub at that latency (see Find the request to make faster).

The card also works out how long the screen took in your app’s real sessions, the ones you and your team used it in. It takes the latency each request had in the newest 200 sessions that no flow ran, and replays the same order of requests at those latencies: catalog: at the latencies 4 real visit(s) measured, ready 339 ms on average (359 ms at worst). With a network entry it adds how many of those visits go over readyMs, and warns when any do. It never fails the card, because the slowest-case check above is the one that does.

The cold-start limits apply to the screen your app opens on, and only in a session that started cold: squiggle card starts the app cold before its first flow. Set them on that screen’s own entry, not on "*". Each phase starts where the one before it ends, so a slower bundle shows up in bundleLoadMs and not in every phase after it. From firstRenderMs on, and in startupToInteractiveMs, the time Squiggle itself holds your app’s JS thread while it attaches its debugger at launch is left out. The phases need your Metro config wrapped in withSquiggle (see Set up your app); without it, nativeLaunchMs, bundleLoadMs and firstRenderMs can report “not measured”.

Budgets are used in two more places. The waterfall-request detector reports a chain longer than the "*" waterfallDepth, and jank-attribution reports a moment that dropped more frames than the "*" droppedFramesPerInteraction; see Findings. And a screen’s frameP95Ms and droppedFramesPerInteraction, its own or from "*", are the limits a flow’s scroll and smooth asserts use when they leave a number out.

Terminal
squiggle perf budgetbudgets every budgeted screen · session mv6rxxns-1  ✔ checkout frameP95Ms: 10.4 of 12 ms, margin 1.6, lost 0.8 this week  ✗ checkout rendersPerTap: 74 of 60 renders, margin -14  · checkout waterfallDepth: not measured (limit 2 requests)

It checks the newest session, or the one you pass with --session <id>. Each line shows how far the screen is from its limit, and how much of that margin it lost or gained this week, so you can see a screen heading for its limit before it gets there. A limit nothing measured reports “not measured”, never a pass. The command exits 1 when any screen is over.

squiggle perf budget --changed checks only the screens your branch changed since it left origin/main, including edits you haven’t committed; --base <ref> compares with another ref. It runs the fewest saved flows that visit those screens, then checks their budgets against those runs. A changed screen that no flow visits is listed under “no flow covers” and isn’t checked. The report card fails on it instead.

Check performance inside a flow

A flow can assert on renders and frames at the step where they matter, so the run fails at that step rather than in a later comparison:

checkout.yaml
- tap: { testID: add-to-cart }- assert:    rerenders: { CartRow: { lt: 3 } }

A scroll or smooth assert that leaves out its frame numbers takes them from the screen’s budget; see Take the numbers from your budgets.

See Assertions. For how long each step of a flow takes, see Benchmark a flow.