Benchmark a flow

For AI agents: this page is Markdown at https://squiggle.sh/docs/run/bench.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.

squiggle bench runs a flow, splits each step's time into five parts, and compares the run with the last one that used the same settings. Use it to see where a run spends its time, and to catch a flow getting slower.

Run a benchmark

Terminal
squiggle bench login10.5s  -57ms (-1%)  vs 10.5s on 2026-07-30 13:41 (74193f7+dirty)flags inproc · transport direct · load 2.1 (was 1.9)settleGate  ██████████████████████████████   3.1s  +36ms (+1%)deliver     █████████████░░░░░░░░░░░░░░░░░   1.4s  +50ms (+4%)stepDelay   ██████████░░░░░░░░░░░░░░░░░░░░   1.1s  ±0ms (0%)rectStable  ███████░░░░░░░░░░░░░░░░░░░░░░░  685ms  +23ms (+3%)resolve     █░░░░░░░░░░░░░░░░░░░░░░░░░░░░░   76ms  -7ms (-8%)phase totals · vs the last same-flags rundropped frames  67 (-20)peak RSS        512.5 MB (-99.5 MB)GC              55 (-19) runs / 132 µs (+19 µs)

The first line compares the total with the last benchmark of this flow that used the same flags. A run with different flags, such as --direct-scroll, is never compared with one without them, and a run in a Niteshift task is never compared with one on your Mac. The bars share one scale, so the part that grew stands out. The last lines are the app’s own numbers for the run. A number Squiggle couldn’t measure shows as n/a, never 0.

To benchmark a React web app, name it by its origin: squiggle bench login --udid web:http://localhost:5173. See React web apps.

Where a step’s time goes

PartWhat it is
settleGateWaiting for the app to stop moving before the step acts. Usually the largest. squiggle flow --settle-debug names what kept it waiting.
resolveFinding the control the selector names.
rectStableWaiting for the control to stop moving, so the tap doesn’t land where it used to be.
deliverThe tap, text or scroll itself.
stepDelayThe short pause after each step.

Every squiggle flow run of more than three steps also ends with a chart of its three slowest steps, and every run writes each step’s timings to .squiggle/runs/.

Watch the trend

Terminal
squiggle bench login --history

--history lists the recent benchmarks of a flow, so slow drift shows as a trend instead of a series of small changes that each look like noise. The history is kept in .squiggle/bench/ on your machine. A React web app’s benchmarks are kept apart from the simulator’s, so the two are never compared: add its --udid web:<origin> to --history to list them.

See what extra renders cost

When a run rendered components more or less often in total than the run it is compared with, the bench says so, and how much render time your own components’ share of that adds or saves:

Terminal
renders +1342 against the baseline (OrderList +11, OrderRow +330, PriceText +330) · predicted +138 ms of render time; measured +38 ms

Each component’s cost per render is the median time its recent renders took on this machine, and only your own components are priced (those with a source file outside node_modules), since a navigator renders around the whole screen. A component’s time includes its children’s, so a list and its rows counted together make the figure larger than the real cost; read it as a direction and a rough size. The measured number is the whole run’s change, and renders that happen while the flow waits for something else may not move it at all.

Find where it got slower

Terminal
squiggle bench login --breaks

--breaks reads the history of runs that passed with the same flags as the newest one and lists where its time changed, without running anything:

  • jump: the time changed between two commits and stayed. For a slowdown, the line gives the squiggle bisect command for that range, with a --budget-ms between the two times, so the bisect looks for the commit that made it slower.
  • machine: the time changed and stayed with no commit between: your Mac, its setup, the app build, or edits you hadn’t committed.
  • episode: a few runs were slower (or faster) and the next ones came back, which is usually a busy machine.
  • drift: the time rose or fell steadily over at least 20 runs.

One slow run on its own is never a break: a change has to last three runs. Times are compared as measured, not adjusted for how busy the machine was. It needs at least six runs that passed with the same flags; with fewer it reports no breaks. Add --json for the list.

Run it several times

Terminal
squiggle bench login --runs 3

--runs 3 runs the flow three times and records one of the runs, not an average: the median one when all three pass. If any run fails, it records the failed run, shows it as red in the history, and exits 1, because a benchmark is also a check that the flow still works:

Terminal
1.9s · 2.6s · 2.7s → recorded the failed run (1.9s)

The runs are 1.5 to 3 seconds apart, a random gap each time, so they do not keep time with anything else that repeats on your machine. Each run records the machine's load average when it started, shown beside the flags. If a run got slower while the load was much higher than last time, the machine was busy: run it again before looking for a cause in the code.

Once at least 8 earlier runs that passed with the same flags show the time rising with the load, a line under the comparison gives the run’s time at the load of the run it is compared with. The trend counts only if it would have helped on the earlier runs: adjusted for load, a typical earlier run must land closer to the run before it than it does unadjusted, so one run on a very busy machine cannot set the trend. With fewer runs, no clear trend, or a trend that would not have helped, it says compared raw and why. Each phase and step gets the same treatment on its own: a phase whose time follows the load is compared at the earlier run’s load, the caption under the phase totals counts how many were, and a step that got slower only because the machine was busier is not listed as a step that moved. Treat adjusted times as a hint: the load average trails what your Mac is doing by up to a minute.

Each run also keeps every step’s render count in the history. Render counts vary far less between runs than times do, so a large change in renders points at the app rather than the machine.

--pr 326 also posts the result as a comment on pull request 326, and updates that comment on the next benchmark instead of adding another. It needs the GitHub CLI, gh.

A failed run is never used as the run to compare against. The next benchmark compares with the last one that passed, and says how many failed runs it passed over. A flow that fails only on some runs usually starts from a different screen each time; give it a prerequisite.

Find the commit that slowed a flow

squiggle bisect runs a flow on the commits between one where it was fine and one where it isn’t, and names the first bad one. Each commit’s JavaScript is served to the app through its own Metro, so nothing is rebuilt, and your checkout and your own Metro are left alone. With --budget-ms, a run slower than the budget counts as bad, so it finds a slowdown as well as a failure:

Terminal
squiggle bisect login --good main~8 --budget-ms 3000 --hunksbisect login: 8 commits, main~8..HEAD  …  3e1c90ab Prefetch order history on sign-in: bad, 4630ms  b72d0f15 Rename the sign-in screen: good, 2710ms  …first bad commit: 3e1c90ab Prefetch order history on sign-in (confirmed by a re-run of it and its parent), 7 runs in 4.6 minhunks in 3e1c90ab: 2  src/orders/useOrders.ts (+9/-2) @@ -14,8 +14,15 @@ export function useOrders() {: without it good, 2740ms, accounts for 1890 of 1920ms  src/auth/signIn.ts (+3/-0) @@ -40,6 +40,9 @@ export async function signIn() {: without it bad, 4610ms, accounts for 20 of 1920msreverting src/orders/useOrders.ts recovers it: 2740ms

A culprit is confirmed when it fails and its parent passes on a second run. If that second run disagrees, bisect says the culprit isn’t confirmed and exits 1, with or without --hunks. --hunks then reverts each change in that commit on its own and reports how much of the slowdown each one accounts for, and which to revert to get the time back. Run times vary, so use --runs 3 to judge each commit by the median of three runs.

Before you start, check that you have:

  • A booted simulator running an Expo development build of the app, with expo.scheme set in app.json. bisect points the development build at each commit through that scheme. If the app isn’t at the project root, pass --app-dir.
  • A range that only changes JavaScript. A commit that changes native code, a dependency, package.json, a lockfile or the Expo config stops bisect before anything runs, with E_BISECT_NATIVE and the commit and file. Bisect the commits after it, or rebuild and test across it by hand.

Bisect a React web app

Pass --platform web. bisect checks each commit out into a worktree, starts that worktree’s own dev server (vite or next dev) on a free port, and opens it in a window of Squiggle’s. Each commit gets a fresh browser context, so no run sees the last one’s storage. Your checkout, your dev server and the window Squiggle already has open are left alone, and nothing has to be running before you start:

Terminal
squiggle bisect checkout --good main~8 --budget-ms 1500 --platform web

If the web app isn’t at the project root, pass --app-dir with its folder. A commit that changes package.json or a lockfile stops bisect the same way as on a device.

When bisect finishes, it sends the app back to the Metro it was on before, whatever port that Metro runs on. If you pressed Ctrl-C, it does the same and removes its worktree before it exits. If the bad end passes, or the good end already fails, bisect says so and exits 1. The flags and exit codes are in the CLI reference.

Compare two implementations

When you can’t decide between two ways to build something, such as a FlatList or a mapped ScrollView, or one store or another, commit each on its own branch and let squiggle bakeoff measure them. It runs one flow on your checkout and on each branch you name, serving each one’s JavaScript through its own Metro the way bisect does, and prints one table:

Terminal
squiggle bakeoff checklist-scroll --against checklist-flatlist --runs 3bakeoff checklist-scroll: HEAD vs checklist-flatlist, 3 runs each  …| revision | passed | flow ms | renders / interaction | dropped frames | memory growth MB | startup ms || --- | --- | --- | --- | --- | --- | --- || HEAD | 3/3 | 8843 | 169.5 | 9 | 49.4 | 1097 || checklist-flatlist | 3/3 | 8782 | 174.5 | 9 | 52.6 | 1097 |

The branches take turns, run by run, so a Mac that gets busier halfway through slows them all alike. Each number is the median of the runs that passed, and each is measured only while its own run was running: renders per tap, swipe or other interaction, frames dropped, how much the app’s memory grew, and how long the app took to start. Here the two lists are level, and the FlatList costs five more renders an interaction, so the ScrollView stays. The table is Markdown, so you can paste it into the pull request.

The same checks as bisect apply: an Expo development build with expo.scheme set, --app-dir when the app isn’t at the project root. When it finishes, the app goes back to the Metro it was on. A branch whose difference from your checkout touches native code or a dependency is refused before anything runs, with E_BAKEOFF_NATIVE. Ctrl-C cleans up the same way it does for bisect. On a React web app, pass --platform web and each revision is served by its own dev server, as for bisect.