[benchmarks] Add local inline-step STSO benchmark - #3232
Conversation
Measures step-to-step overhead for steps that run eagerly inline — many sequential steps inside a single flow-handler invocation, no queue hop. Runs against @workflow/world-local, so it needs no deployment (unlike packages/core/e2e/benchmark.test.ts). Findings at 1000 null steps (see RESULTS-1000.txt): - The in-process loop re-executes the workflow function once per step: 1000 steps => 1 flow invocation, 1001 replays, 3 events/step in the log. - STSO(i) ~= 7.3 ms + 0.074 ms * i. First few steps ~8 ms, step 1000 ~80 ms (~10x). Total is quadratic: 44 s, of which 35 s is replay and ~1 ms is step-body work. - Replay overtakes world I/O around step 15-20 and is ~80% of the gap past step 300. A step's return value doubles the slope, but not because of its size (RESULTS-payload-600.txt). ReplayPayloadCache memoizes the hydrated value only for primitives <= MAX_MEMOIZED_PRIMITIVE_LENGTH; everything else re-hydrates against each fresh VM realm. So a 4000-char string costs the same as returning nothing (0.028 ms/step) while a 5000-char string costs 0.074, and a 40-byte object costs the same as a 5 KB string. 15x the object payload moves the slope 7% — the penalty is mostly the per-hydration reviver-table construction, not decoding. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Shalabh Chaturvedi <7066873+shalabhc@users.noreply.github.com> Co-Authored-By: Shalabh Chaturvedi <7066873+shalabhc@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 448ee39 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🧪 E2E Test Results❌ Some tests failed ❌ Failed E2E Tests▲ Vercel Production (2 failed)nextjs-webpack (1 failed):
nitro (1 failed):
📦 Local Production (1 failed)nextjs-webpack-stable (1 failed):
📋 Other (1 failed)e2e-vercel-prod-tanstack-start (1 failed):
E2E Test SummarySummary
Details by Category❌ ▲ Vercel Production
✅ 💻 Local Development
❌ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
❌ 📋 Other
✅ vercel-multi-region
|
📊 Workflow Benchmarkscommit Backend:
📈 STSO distribution vs main (inline / queue-hop histograms)1020 steps (inline) Cumulative STSO time: main 408200ms → this run 410851ms (Δ +2651ms, +1%) 1020 steps (queue-hop) Cumulative STSO time: main 7007ms → this run 7918ms (Δ +911ms, +13%) ℹ️ Metric definitions & methodologyThe collapsed STSO distribution section above buckets every step gap of the sequential-steps run (not a sampled window), split by whether the step ending the gap ran inline — in the same warm process as the step before it, so the gap is pure framework overhead — or after a queue-hop — the first step of a fresh process, which pays queue dispatch, client reinit and event-log replay. Bars overlay the two runs: Best/P75/P90/P99 deltas compare against the most recent benchmark run on Metrics — TTFS: time to first step body (in-deployment start() → first step body, deployment clocks) · STSO: step-to-step overhead (gap between consecutive step bodies) · WO: workflow overhead (whole-run time outside step bodies, in-deployment anchored) · SL: stream latency (in-deployment write → read propagation, readAt - writtenAt) · SO: stream overhead (end-to-end write+consume time beyond the modelled generation window) Scenarios — step: one trivial no-op step, no stream; no hooks, so the run stays in turbo mode (in-process fast path) · stream: one streaming step; no hooks, so the run stays in turbo mode (in-process fast path) · hook + stream: registers a hook before one step, which exits turbo mode (dispatch path) · 1020 steps: 1020 trivial sequential steps; STSO is measured between consecutive steps in the given step ranges, and WO is the whole-run overhead outside step bodies · stream latency: parallel reader/writer steps on a dedicated stream; SL is the in-deployment write->read propagation (readAt - writtenAt) · stream overhead (text): writer streams 300 variable-length text token deltas paced at 100/s for 3s (a haiku-size LLM's token throughput) while a parallel reader drains the whole stream; SO is the end-to-end write+consume time beyond the 3s generation window (overhead/backpressure) · stream overhead (structured): same workload as stream overhead (text), but each delta is an AI-SDK-style structured object ({ type: 'text-delta', id, text }) instead of a raw string, so the SO gap vs the text scenario is the added serialization cost 🔴 marks a percentile over its target (within target is left unmarked). Targets (p75/p90/p99, ms) — TTFS 200/300/600 · SL 50/60/125 · SO 250/500/1000 All metrics are measured from deployment-side timestamps only. Runs are triggered by an in-deployment route that stamps the anchor ( Cold starts are kept in the numbers on purpose — they are part of real bursty-workload latency. The workbench deployment cold-starts the |
Description
Adds
workbench/inline-step-bench, a local benchmark for step-to-step overhead (STSO) when steps run eagerly inline — many sequential steps inside a single flow-handler invocation, with no queue hop between them. It runs against@workflow/world-local, so unlikepackages/core/e2e/benchmark.test.tsit needs no deployment.Nothing in
packages/*is touched; this is workbench + docs only.What it measures
A workflow of N sequential no-op steps. Each body stamps
performance.now()on entry/exit, soSTSO[i] = t0[i] − t1[i−1]is pure runtime overhead. The driver also parses the runtime's ownDEBUG=workflow:runtime:debugoutput (Starting workflow replay/Workflow suspended) to split each gap into replay vs world I/O.Findings at 1000 null steps (
RESULTS-1000.txt)STSO(i) ≈ 7.3 ms + 0.074 ms × i. First few steps ~8 ms, step 1000 ~80 ms (~10×). Total is quadratic: 44 s, of which 35 s is replay and ~1 ms is step-body work.WORKFLOW_TURBO=0does not change the slope — turbo removes start-up round-trips, not replay.The return-value cliff (
RESULTS-payload-600.txt)A step's return value doubles the slope, but not because of its size.
ReplayPayloadCachememoizes the hydrated value only for primitives ≤MAX_MEMOIZED_PRIMITIVE_LENGTH(4096); everything else re-hydrates against each fresh VM realm.undefinedA 4 KB string is as cheap as returning nothing; 25% more string is 2.6× the slope; a 40-byte object costs the same as a 5 KB string; 15× the object payload moves it 7%. The penalty is mostly the per-hydration reviver-table construction in
deserializePreparedReplayPayload(getWorkflowRevivers(global)allocates a fresh closure table per step per replay), not decoding.How did you test your changes?
This is a benchmark, so the artifact is the test run. Committed outputs are full runs on the machine described at the top of each file:
RESULTS-1000.txt— 5 scenarios × 1000 stepsRESULTS-payload-600.txt— 6 scenarios × 600 stepsCorrectness self-checks the harness asserts inline on every run: exactly one flow-handler invocation, exactly N step bodies each executed once, 3 events/step, and
loopIterationreaching N+1.npx biome check workbench/inline-step-bench/exits 0.Warning
Reviewer caveats, please push back on these:
world-localis a filesystem world; its fixed per-step term is not a Vercel latency prediction, and itsotherterm drifts up because the inline-delta cursor queryreaddirs a directory of 3000 event files. Only the slopes and ratios are portable. Committed benchmark output tends to get quoted without its caveats — happy to strip the absolute numbers down to slopes if preferred.runScenarioinbench.mjstripsnoExcessiveCognitiveComplexity(34 vs 15). It'swarn-level so lint passes, but I can split the reporting out.workbench/at all, or be folded intopackages/core/e2e/benchmark.test.tsas a local-world mode?PR Checklist - Required to merge
pnpm changesetwas run to create a changelog for this PR — empty changeset (workbench app only)@vercel/workflowin a comment once the PR is ready, and the above checklist is complete🤖 Generated with Claude Code