perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

perf(core): drain consumable replay events synchronously - #2473

Merged
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops
Jun 18, 2026
Merged

perf(core): drain consumable replay events synchronously#2473
pranaygp merged 3 commits into
mainfrom
pgp/perf-reduce-macrotask-hops

Conversation

@pranaygp

@pranaygppranaygp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Perf optimization #5reduce macrotask hops on the suspension/consume replay hot path.

EventsConsumer.consume rescheduled process.nextTick(this.consume) after every consumed event, so replaying N already-consumable events (structural lifecycle events, step_created/step_started, completed deliveries) cost N macrotask hops — O(N) per consume wave across a sequential replay. This drains consecutively consumable events in a single synchronous pass instead (O(N) hops → 1 per replay wave).

scheduleWhenIdle's initial setTimeout(0) is deliberately kept — it is load-bearing for cross-VM propagation and a comment now records why (see below).

Why the synchronous drain is safe

Callbacks only ever consume events whose consumer is already registered. New consumers are registered by workflow VM body code that runs asynchronously off ctx.promiseQueue after a delivery resolve(). When the next event's consumer is not yet registered, no callback consumes it and we fall through to the existing cross-VM-safe deferred unconsumed-event check, exactly as before — the synchronous drain does not change that path. A null end-of-events sentinel never continues the drain, so it cannot spin past end-of-log.

scheduleWhenIdle is unchanged: between a delivery's resolve() and the VM body re-subscribing, pendingDeliveries is already 0, and Node does not guarantee a host microtask settles after the cross-VM chain. Empirically, downgrading its setTimeout(0) to queueMicrotask breaks hook/sleep Promise.race ordering (CorruptedEventLogError). A comment in packages/core/src/private.ts now captures this invariant.

A note on the earlier revert (it was premature)

An earlier round reverted this optimization down to a comment-only change after a singleworld-testinginline-batches-debug failure on the windows-latest Unit job, attributing it to a cross-VM replay divergence caused by the drain.

I re-validated that conclusion empirically and it does not hold — the failure is a pre-existing flake in that test on Windows, unrelated to this change:

  • Main reproduces the identical failure with zero optimization present. A historical scan of windows-latest Unit runs on unmodified main shows ~13% (10/76) flake rate, and the exact inline-batches-debug 60s timeout occurs on bare main (e.g. commit 4a5a23088, run 27474356210). The failure mode is a self-healing replay-divergence retry that eventually times out — not a thrown CorruptedEventLogError.
  • Local 8-way concurrent stress (10 waves × 8 = 80 runs each): optimization 4/80 (5.0%) vs unmodified main7/80 (8.75%) — the optimization flakes less, with an identical divergence-retry failure mode on both arms. Isolated low-load: optimization 40/40 pass.
  • Fresh Windows CI (8 parallel runs of the real Unit Tests (windows-latest) job, confirmed not fast-path skipped): optimization 4/4 pass (runs 27739171715, 27739454028, 27739455535, 27739457404; plus an earlier confirming run = 5/5), main baseline 4/4 pass (runs 27739493993, 27739495175, 27739497219, 27739498448).

A single failure against a measured ~5–13% baseline flake rate is statistically meaningless, and the optimization's restored code is byte-for-byte identical to the original commit. Conclusion: flake, not a regression — the optimization is restored.

Verification

  • cd packages/core && pnpm test (the CI Unit command, WORKFLOW_TARGET_WORLD=local vitest run src) — 1237 passed, 0 failed, including the new drain test, suspension/replay/hook/wait/Promise.race ordering.
  • world-testinginline-batches-debug — 3/3 pass locally on the restored branch.
  • biome / pre-commit — clean; restored code byte-identical to the original optimization commit.

Changeset

'@workflow/core': patch — "Drain consecutively consumable replay events in a single synchronous pass instead of one process.nextTick per event, removing O(N) macrotask hops from replay."

@pranaygp
pranaygp requested a review from a team as a code ownerJune 17, 2026 01:49
CopilotAI review requested due to automatic review settings June 17, 2026 01:49
@changeset-bot

changeset-botBot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercelBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express0.045s (+3.0%)1.006s (~)0.961s101.00x
💻 LocalNitro0.046s (+13.3% 🔺)1.005s (~)0.959s101.03x
💻 LocalNext.js (Turbopack)0.050s (-24.9% 🟢)1.005s (~)0.955s101.11x
🐘 PostgresNitro0.064s (+1.8%)1.012s (~)0.948s101.43x
🐘 PostgresExpress0.067s (-7.4% 🟢)1.012s (~)0.945s101.50x
🐘 PostgresNext.js (Turbopack)0.069s (-1.6%)1.012s (~)0.942s101.55x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)0.262s (-10.1% 🟢)2.234s (+18.1% 🔺)1.972s101.00x
▲ VercelNitro0.322s (-14.2% 🟢)2.374s (+5.6% 🔺)2.052s101.23x
▲ VercelExpress0.420s (+11.3% 🔺)2.881s (+25.5% 🔺)2.461s101.60x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.092s (+0.7%)2.006s (~)0.914s101.00x
💻 LocalExpress1.101s (~)2.007s (~)0.906s101.01x
🐘 PostgresNitro1.107s (-1.2%)2.008s (~)0.901s101.01x
💻 LocalNext.js (Turbopack)1.109s (-3.4%)2.005s (~)0.896s101.02x
🐘 PostgresExpress1.114s (+0.6%)2.010s (~)0.896s101.02x
🐘 PostgresNext.js (Turbopack)1.151s (+0.8%)2.011s (~)0.860s101.05x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.977s (+2.1%)3.851s (+4.8%)1.875s101.00x
▲ VercelNext.js (Turbopack)2.000s (+13.3% 🔺)4.059s (+9.3% 🔺)2.059s101.01x
▲ VercelNitro2.150s (-7.2% 🟢)4.255s (+6.6% 🔺)2.106s101.09x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.559s (~)11.022s (~)0.463s31.00x
🐘 PostgresNitro10.568s (~)11.016s (~)0.448s31.00x
🐘 PostgresExpress10.571s (~)11.019s (~)0.448s31.00x
💻 LocalExpress10.571s (~)11.022s (~)0.451s31.00x
💻 LocalNext.js (Turbopack)10.584s (-2.0%)11.020s (~)0.436s31.00x
🐘 PostgresNext.js (Turbopack)10.881s (~)11.021s (~)0.140s31.03x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express15.626s (-13.5% 🟢)17.305s (-13.3% 🟢)1.679s21.00x
▲ VercelNext.js (Turbopack)16.707s (+16.7% 🔺)18.292s (+12.2% 🔺)1.584s21.07x
▲ VercelNitro17.793s (-6.2% 🟢)19.929s (-6.5% 🟢)2.137s21.14x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro13.833s (+1.5%)14.027s (~)0.193s51.00x
🐘 PostgresNitro13.864s (~)14.024s (~)0.160s51.00x
🐘 PostgresExpress13.889s (~)14.021s (~)0.132s51.00x
💻 LocalExpress13.894s (+1.0%)14.026s (~)0.132s51.00x
💻 LocalNext.js (Turbopack)13.990s (-2.6%)14.225s (-5.4% 🟢)0.234s51.01x
🐘 PostgresNext.js (Turbopack)14.699s (+1.9%)15.023s (~)0.323s41.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express23.844s (-1.5%)25.446s (-2.8%)1.602s31.00x
▲ VercelNitro24.086s (-22.7% 🟢)25.915s (-20.4% 🟢)1.829s31.01x
▲ VercelNext.js (Turbopack)24.694s (-30.3% 🟢)26.367s (-28.4% 🟢)1.673s31.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Express12.552s (~)13.027s (~)0.475s71.00x
🐘 PostgresNitro12.588s (+0.6%)13.017s (~)0.429s71.00x
💻 LocalNitro12.590s (+4.3%)13.024s (+1.0%)0.434s71.00x
🐘 PostgresExpress12.665s (+1.8%)13.019s (~)0.354s71.01x
💻 LocalNext.js (Turbopack)13.123s (-3.9%)13.595s (-3.1%)0.473s71.05x
🐘 PostgresNext.js (Turbopack)14.006s (+1.0%)14.303s (+1.0%)0.297s71.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro31.844s (-18.2% 🟢)34.522s (-15.7% 🟢)2.677s31.00x
▲ VercelNext.js (Turbopack)33.833s (-3.9%)36.095s (-2.2%)2.261s31.06x
▲ VercelExpress34.180s (-2.5%)36.529s (-1.0%)2.349s31.07x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.199s (~)2.008s (~)0.808s151.00x
🐘 PostgresExpress1.211s (~)2.008s (~)0.797s151.01x
💻 LocalNitro1.228s (+5.0% 🔺)2.007s (~)0.778s151.02x
💻 LocalExpress1.266s (+8.7% 🔺)2.006s (~)0.740s151.06x
🐘 PostgresNext.js (Turbopack)1.283s (~)2.008s (~)0.725s151.07x
💻 LocalNext.js (Turbopack)1.298s (~)2.006s (~)0.708s151.08x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.290s (-21.4% 🟢)3.958s (-10.2% 🟢)1.668s81.00x
▲ VercelExpress2.476s (+11.6% 🔺)3.811s (-1.9%)1.335s81.08x
▲ VercelNext.js (Turbopack)2.511s (-5.9% 🟢)4.007s (-2.2%)1.495s81.10x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.289s (-5.6% 🟢)2.008s (-20.0% 🟢)0.719s151.00x
🐘 PostgresExpress1.399s (-1.8%)2.076s (-13.3% 🟢)0.677s151.09x
🐘 PostgresNext.js (Turbopack)1.485s (-9.3% 🟢)2.315s (-3.3%)0.830s131.15x
💻 LocalNext.js (Turbopack)2.004s (+4.9%)2.590s (+13.0% 🔺)0.587s121.55x
💻 LocalExpress2.009s (+23.5% 🔺)2.509s (+25.1% 🔺)0.501s121.56x
💻 LocalNitro2.120s (+36.6% 🔺)2.829s (+40.7% 🔺)0.709s111.64x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.643s (-34.7% 🟢)4.313s (-24.3% 🟢)1.670s71.00x
▲ VercelExpress2.704s (-31.7% 🟢)4.665s (-17.8% 🟢)1.961s71.02x
▲ VercelNext.js (Turbopack)3.003s (-33.1% 🟢)5.042s (-22.2% 🟢)2.039s61.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.438s (-9.9% 🟢)3.454s (-13.9% 🟢)2.016s91.00x
🐘 PostgresExpress1.563s (-11.3% 🟢)4.012s (+3.2%)2.449s81.09x
🐘 PostgresNext.js (Turbopack)2.506s (-20.6% 🟢)3.346s (-22.3% 🟢)0.841s91.74x
💻 LocalNext.js (Turbopack)4.685s (-18.9% 🟢)5.010s (-19.4% 🟢)0.325s63.26x
💻 LocalExpress5.474s (+25.2% 🔺)6.015s (+23.6% 🔺)0.541s53.81x
💻 LocalNitro5.492s (+60.4% 🔺)6.018s (+50.1% 🔺)0.526s53.82x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.923s (-28.7% 🟢)6.106s (-23.0% 🟢)2.183s51.00x
▲ VercelNitro4.522s (-26.2% 🟢)7.044s (-15.5% 🟢)2.522s51.15x
▲ VercelNext.js (Turbopack)4.615s (-18.0% 🟢)6.740s (-12.7% 🟢)2.125s51.18x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.210s (~)2.008s (~)0.798s151.00x
🐘 PostgresExpress1.218s (~)2.008s (~)0.790s151.01x
💻 LocalExpress1.240s (-21.4% 🟢)2.007s (~)0.767s151.02x
💻 LocalNitro1.280s (+6.6% 🔺)2.007s (~)0.727s151.06x
🐘 PostgresNext.js (Turbopack)1.300s (+1.5%)2.007s (~)0.707s151.07x
💻 LocalNext.js (Turbopack)1.352s (-3.3%)2.006s (~)0.654s151.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.428s (-34.7% 🟢)3.926s (-24.9% 🟢)1.498s81.00x
▲ VercelExpress2.580s (+11.1% 🔺)3.902s (+2.5%)1.321s81.06x
▲ VercelNitro2.710s (-24.0% 🟢)4.379s (-17.2% 🟢)1.669s71.12x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.279s (-11.4% 🟢)2.007s (-16.2% 🟢)0.729s151.00x
🐘 PostgresExpress1.338s (-2.0%)2.074s (-10.4% 🟢)0.736s151.05x
🐘 PostgresNext.js (Turbopack)1.468s (-4.9%)2.009s (-9.6% 🟢)0.541s151.15x
💻 LocalNitro1.941s (+14.6% 🔺)2.393s (+19.1% 🔺)0.451s131.52x
💻 LocalExpress2.038s (+7.4% 🔺)2.737s (+27.4% 🔺)0.699s111.59x
💻 LocalNext.js (Turbopack)2.071s (-4.5%)2.676s (-11.1% 🟢)0.606s121.62x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.762s (+1.3%)4.392s (-3.9%)1.630s71.00x
▲ VercelNitro2.973s (+6.2% 🔺)5.012s (+19.8% 🔺)2.039s61.08x
▲ VercelNext.js (Turbopack)3.377s (-24.4% 🟢)5.066s (-17.7% 🟢)1.689s61.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.432s (-20.6% 🟢)3.887s (-9.5% 🟢)2.455s81.00x
🐘 PostgresExpress1.459s (-18.9% 🟢)4.013s (~)2.554s81.02x
🐘 PostgresNext.js (Turbopack)2.346s (-42.3% 🟢)3.344s (-24.8% 🟢)0.998s91.64x
💻 LocalNext.js (Turbopack)4.868s (-16.1% 🟢)5.344s (-16.7% 🟢)0.476s63.40x
💻 LocalNitro5.648s (+25.8% 🔺)6.014s (+20.0% 🔺)0.365s53.94x
💻 LocalExpress6.149s (+34.0% 🔺)7.016s (+40.0% 🔺)0.867s54.29x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.378s (-59.9% 🟢)5.574s (-45.6% 🟢)2.196s61.00x
▲ VercelNitro3.792s (-72.6% 🟢)5.866s (-62.5% 🟢)2.075s61.12x
▲ VercelNext.js (Turbopack)4.105s (+8.5% 🔺)6.304s (+20.5% 🔺)2.198s51.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro0.570s (-4.1%)1.006s (-3.4%)0.436s601.00x
💻 LocalNitro0.604s (+20.6% 🔺)1.005s (~)0.401s601.06x
🐘 PostgresExpress0.631s (+10.6% 🔺)1.024s (+1.8%)0.393s591.11x
💻 LocalExpress0.633s (+1.3%)1.005s (-1.7%)0.372s601.11x
💻 LocalNext.js (Turbopack)0.693s (-22.0% 🟢)1.005s (-3.3%)0.312s601.22x
🐘 PostgresNext.js (Turbopack)0.833s (~)1.023s (~)0.190s591.46x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.915s (-40.8% 🟢)5.510s (-33.9% 🟢)1.595s111.00x
▲ VercelNext.js (Turbopack)3.970s (-37.1% 🟢)5.751s (-29.4% 🟢)1.781s111.01x
▲ VercelExpress4.120s (-9.4% 🟢)5.873s (-9.4% 🟢)1.753s111.05x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.349s (-2.8%)2.007s (-1.1%)0.657s451.00x
🐘 PostgresExpress1.446s (+6.6% 🔺)2.030s (~)0.584s451.07x
💻 LocalNitro1.544s (+30.0% 🔺)2.007s (~)0.463s451.14x
💻 LocalExpress1.574s (+5.8% 🔺)2.007s (~)0.433s451.17x
💻 LocalNext.js (Turbopack)1.702s (-19.0% 🟢)2.005s (-33.3% 🟢)0.304s451.26x
🐘 PostgresNext.js (Turbopack)1.979s (+2.0%)2.316s (+11.6% 🔺)0.337s391.47x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express10.284s (-41.2% 🟢)12.097s (-36.9% 🟢)1.812s81.00x
▲ VercelNitro10.315s (-12.7% 🟢)12.425s (-12.3% 🟢)2.110s81.00x
▲ VercelNext.js (Turbopack)11.472s (-15.6% 🟢)13.232s (-13.6% 🟢)1.759s71.12x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.740s (-2.1%)3.111s (-1.7%)0.371s391.00x
🐘 PostgresExpress2.846s (+5.0% 🔺)3.193s (+2.7%)0.347s381.04x
💻 LocalNitro3.362s (+23.1% 🔺)4.010s (+24.5% 🔺)0.648s301.23x
💻 LocalExpress3.421s (+7.0% 🔺)4.010s (~)0.588s301.25x
💻 LocalNext.js (Turbopack)3.553s (-18.2% 🟢)4.008s (-20.0% 🟢)0.455s301.30x
🐘 PostgresNext.js (Turbopack)3.877s (~)4.043s (-0.8%)0.167s301.41x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro21.352s (-18.8% 🟢)24.093s (-14.3% 🟢)2.740s61.00x
▲ VercelExpress21.701s (-16.8% 🟢)23.943s (-14.6% 🟢)2.243s61.02x
▲ VercelNext.js (Turbopack)24.271s (-2.9%)26.569s (-0.8%)2.298s51.14x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.245s (+5.8% 🔺)1.007s (~)0.762s601.00x
🐘 PostgresNitro0.279s (+18.4% 🔺)1.023s (+1.7%)0.745s591.14x
🐘 PostgresNext.js (Turbopack)0.287s (-2.3%)1.006s (~)0.719s601.17x
💻 LocalExpress0.428s (-2.8%)1.005s (~)0.577s601.75x
💻 LocalNitro0.446s (+19.6% 🔺)1.005s (~)0.559s601.82x
💻 LocalNext.js (Turbopack)0.542s (-7.0% 🟢)1.004s (~)0.462s602.21x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.430s (-23.6% 🟢)2.935s (-24.5% 🟢)1.505s211.00x
▲ VercelNitro1.562s (+21.0% 🔺)3.231s (+12.5% 🔺)1.669s191.09x
▲ VercelExpress1.614s (+4.1%)3.159s (+10.1% 🔺)1.545s191.13x

🔍 Observability: Next.js (Turbopack) | Nitro | Express

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.354s (~)1.018s (-2.1%)0.664s891.00x
🐘 PostgresNitro0.358s (+4.7%)1.041s (+2.4%)0.683s871.01x
🐘 PostgresNext.js (Turbopack)0.446s (-17.2% 🟢)1.041s (-6.9% 🟢)0.595s871.26x
💻 LocalExpress2.131s (+2.0%)2.687s (+1.2%)0.556s346.02x
💻 LocalNitro2.179s (+42.9% 🔺)2.767s (+28.5% 🔺)0.588s336.16x
💻 LocalNext.js (Turbopack)2.404s (+3.1%)3.009s (-2.2%)0.605s306.79x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express2.009s (-31.3% 🟢)3.769s (-21.5% 🟢)1.760s241.00x
▲ VercelNitro2.397s (-12.7% 🟢)4.351s (-9.0% 🟢)1.954s211.19x
▲ VercelNext.js (Turbopack)2.913s (-4.3%)4.492s (-6.2% 🟢)1.579s211.45x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.553s (-2.8%)1.078s (-11.4% 🟢)0.525s1121.00x
🐘 PostgresNitro0.580s (+2.0%)1.161s (-5.7% 🟢)0.581s1041.05x
🐘 PostgresNext.js (Turbopack)1.696s (-35.2% 🟢)2.642s (-23.9% 🟢)0.946s463.07x
💻 LocalNext.js (Turbopack)8.910s (-17.2% 🟢)10.111s (-12.6% 🟢)1.202s1216.12x
💻 LocalNitro9.944s (+57.5% 🔺)10.863s (+61.1% 🔺)0.920s1217.99x
💻 LocalExpress10.043s (+20.9% 🔺)10.697s (+20.4% 🔺)0.654s1218.17x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express3.569s (-34.7% 🟢)5.583s (-21.2% 🟢)2.014s221.00x
▲ VercelNitro3.682s (-30.2% 🟢)5.778s (-17.7% 🟢)2.096s211.03x
▲ VercelNext.js (Turbopack)4.408s (-8.9% 🟢)6.278s (-3.9%)1.870s201.24x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.169s (-3.4%)2.002s (~)0.008s (-36.0% 🟢)2.013s (~)0.844s101.00x
🐘 PostgresNitro1.170s (+0.5%)1.999s (~)0.001s (+10.0% 🔺)2.011s (~)0.841s101.00x
🐘 PostgresExpress1.172s (-0.6%)2.002s (~)0.001s (+18.2% 🔺)2.012s (~)0.840s101.00x
💻 LocalExpress1.175s (+2.2%)2.005s (~)0.013s (+23.8% 🔺)2.020s (~)0.845s101.01x
💻 LocalNitro1.177s (+5.4% 🔺)2.006s (~)0.013s (-54.3% 🟢)2.021s (-0.8%)0.843s101.01x
🐘 PostgresNext.js (Turbopack)1.243s (+1.0%)2.001s (~)0.002s (+15.4% 🔺)2.011s (~)0.768s101.06x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.479s (-1.7%)3.650s (-4.5%)0.868s (+7.5% 🔺)4.971s (-2.2%)2.492s101.00x
▲ VercelExpress2.631s (+9.5% 🔺)3.621s (-1.6%)0.854s (+15.2% 🔺)5.026s (+3.1%)2.395s101.06x
▲ VercelNitro2.669s (+1.1%)3.857s (+1.3%)0.860s (+8.4% 🔺)5.284s (+4.5%)2.615s101.08x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.595s (-8.8% 🟢)2.008s (~)0.009s (-27.8% 🟢)2.020s (~)0.424s301.00x
💻 LocalNitro1.602s (+11.4% 🔺)2.010s (~)0.013s (-25.3% 🟢)2.025s (~)0.423s301.00x
💻 LocalExpress1.606s (+2.5%)2.010s (~)0.013s (-1.6%)2.025s (~)0.419s301.01x
🐘 PostgresExpress1.650s (+4.2%)2.004s (~)0.005s (+7.9% 🔺)2.027s (~)0.377s301.03x
🐘 PostgresNitro1.685s (+6.8% 🔺)2.002s (~)0.005s (-4.9%)2.026s (~)0.341s301.06x
🐘 PostgresNext.js (Turbopack)1.779s (~)2.010s (~)0.005s (-1.9%)2.026s (~)0.247s301.12x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro6.933s (-3.2%)8.590s (-0.8%)0.270s (+13.8% 🔺)9.534s (+1.3%)2.601s71.00x
▲ VercelExpress7.439s (+16.5% 🔺)8.668s (+11.0% 🔺)0.251s (+40.2% 🔺)9.427s (+11.5% 🔺)1.988s71.07x
▲ VercelNext.js (Turbopack)7.485s (-11.9% 🟢)8.787s (-10.5% 🟢)0.161s (-38.9% 🟢)9.358s (-11.5% 🟢)1.872s71.08x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express0.838s (+9.7% 🔺)1.106s (+7.9% 🔺)0.000s (+58.3% 🔺)1.128s (+6.9% 🔺)0.290s541.00x
🐘 PostgresNitro0.838s (+8.4% 🔺)1.104s (+5.3% 🔺)0.000s (+1.9%)1.119s (+2.4%)0.281s541.00x
🐘 PostgresNext.js (Turbopack)0.972s (-4.7%)1.334s (-8.9% 🟢)0.000s (-100.0% 🟢)1.341s (-8.9% 🟢)0.369s451.16x
💻 LocalNitro1.496s (+39.2% 🔺)2.015s (+9.7% 🔺)0.001s (-41.1% 🟢)2.017s (+9.6% 🔺)0.521s301.79x
💻 LocalExpress1.550s (+13.8% 🔺)2.014s (~)0.000s (+116.7% 🔺)2.017s (~)0.467s301.85x
💻 LocalNext.js (Turbopack)1.615s (+6.7% 🔺)2.045s (+1.6%)0.000s (+55.6% 🔺)2.048s (+1.6%)0.434s301.93x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.925s (-15.2% 🟢)4.120s (-13.6% 🟢)0.001s (+928.6% 🔺)4.521s (-14.1% 🟢)1.596s141.00x
▲ VercelExpress3.000s (-1.0%)4.341s (-4.9%)0.000s (NaN%)4.796s (-4.8%)1.795s131.03x
▲ VercelNitro3.183s (-15.3% 🟢)4.661s (-13.4% 🟢)0.000s (-100.0% 🟢)5.170s (-11.8% 🟢)1.987s121.09x

🔍 Observability: Next.js (Turbopack) | Express | Nitro

fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.901s (+22.6% 🔺)2.396s (+12.3% 🔺)0.000s (-100.0% 🟢)2.414s (+12.5% 🔺)0.513s251.00x
🐘 PostgresExpress1.936s (+19.9% 🔺)2.538s (+23.0% 🔺)0.000s (NaN%)2.551s (+22.1% 🔺)0.615s241.02x
🐘 PostgresNext.js (Turbopack)2.004s (-5.1% 🟢)2.426s (-6.2% 🟢)0.000s (-7.7% 🟢)2.435s (-6.2% 🟢)0.430s261.05x
💻 LocalNext.js (Turbopack)3.485s (+20.2% 🔺)4.086s (+21.7% 🔺)0.001s (+180.0% 🔺)4.095s (+21.8% 🔺)0.609s151.83x
💻 LocalNitro4.109s (+86.3% 🔺)4.644s (+69.4% 🔺)0.001s (-43.6% 🟢)4.651s (+68.9% 🔺)0.541s132.16x
💻 LocalExpress4.306s (+47.0% 🔺)4.953s (+34.9% 🔺)0.001s (+292.3% 🔺)4.963s (+35.1% 🔺)0.657s132.26x

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express5.027s (-11.7% 🟢)6.388s (-11.6% 🟢)0.000s (NaN%)6.960s (-9.5% 🟢)1.933s91.00x
▲ VercelNitro5.096s (-2.9%)6.676s (+3.4%)0.000s (+Infinity% 🔺)7.151s (+3.3%)2.055s91.01x
▲ VercelNext.js (Turbopack)5.230s (-27.8% 🟢)6.553s (-22.0% 🟢)0.000s (-11.1% 🟢)6.999s (-20.9% 🟢)1.769s91.04x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro9/21
🐘 PostgresNitro16/21
▲ VercelExpress10/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres17/21
Next.js (Turbopack)🐘 Postgres11/21
Nitro🐘 Postgres16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Redis + BullMQ: Community world (local development)
  • 🌐 Cloudflare: Community world (local development)
  • 🌐 MySQL: Community world (local development)
  • 🌐 Azure: Community world (local development)
  • 🌐 NATS JetStream: Community world (local development)
  • 🌐 Upstash: Community world (local development)

📋 View full workflow run

@github-actions

github-actionsBot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production144202301672
✅ 💻 Local Development190902192128
✅ 📦 Local Production190902192128
✅ 🐘 Local Postgres189502332128
✅ 🪟 Windows15200152
✅ 📋 Other88501791064
Total8192010809272

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro125027
✅ example125027
✅ express125027
✅ fastify125027
✅ hono125027
✅ nextjs-turbopack14903
✅ nextjs-webpack14903
✅ nitro125027
✅ nuxt125027
✅ sveltekit14408
✅ vite125027
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable127025
✅ express-stable127025
✅ fastify-stable127025
✅ hono-stable127025
✅ nextjs-turbopack-canary133019
✅ nextjs-turbopack-stable-lazy-discovery-disabled15200
✅ nextjs-turbopack-stable-lazy-discovery-enabled15200
✅ nextjs-webpack-canary133019
✅ nextjs-webpack-stable-lazy-discovery-disabled15200
✅ nextjs-webpack-stable-lazy-discovery-enabled15200
✅ nitro-stable127025
✅ nuxt-stable127025
✅ sveltekit-stable14606
✅ vite-stable127025
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable126026
✅ express-stable126026
✅ fastify-stable126026
✅ hono-stable126026
✅ nextjs-turbopack-canary132020
✅ nextjs-turbopack-stable-lazy-discovery-disabled15101
✅ nextjs-turbopack-stable-lazy-discovery-enabled15101
✅ nextjs-webpack-canary132020
✅ nextjs-webpack-stable-lazy-discovery-disabled15101
✅ nextjs-webpack-stable-lazy-discovery-enabled15101
✅ nitro-stable126026
✅ nuxt-stable126026
✅ sveltekit-stable14507
✅ vite-stable126026
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack15200
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable127025
✅ e2e-local-dev-tanstack-start-127025
✅ e2e-local-postgres-nest-stable126026
✅ e2e-local-postgres-tanstack-start-126026
✅ e2e-local-prod-nest-stable127025
✅ e2e-local-prod-tanstack-start-127025
✅ e2e-vercel-prod-tanstack-start125027

📋 View full workflow run

Revert the synchronous consume-loop drain optimization: it caused a
replay divergence (ReplayDivergenceError on step_started →
CorruptedEventLogError) in the world-testing inline-batches parallel
workflow on the Windows CI runner. The per-event `process.nextTick` in
the consume loop is load-bearing — it guarantees at most one event is
consumed per macrotask, letting the cross-VM `resolve → workflow VM body
→ subscribe()` chain register the next operation's consumer before the
drain advances. A synchronous drain races ahead of that registration.
What remains is a documentation comment on `scheduleWhenIdle` capturing
why its initial `setTimeout(0)` must not be downgraded to a microtask
(empirically: queueMicrotask breaks hook/sleep Promise.race ordering →
CorruptedEventLogError). No behavior change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pranaygp
pranaygpforce-pushed the pgp/perf-reduce-macrotask-hops branch from b9c9e19 to 5039d82CompareJune 17, 2026 17:45
@pranaygppranaygp changed the title perf(core): drain consumable replay events synchronouslydocs(core): document why scheduleWhenIdle's macrotask is load-bearing (consume-drain perf reverted)Jun 17, 2026

@TooTallNateTooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — correctly-scoped microtask-reduction on the consume hot path

Tight, well-bounded change: EventsConsumer.consume drained one event per process.nextTick, so replaying N consecutively-consumable events (the lifecycle consumer walking run_createdrun_started, a step consumer walking step_createdstep_startedstep_completed) cost N macrotask hops. This drains them in one synchronous while loop via the extracted consumeOne, deferring only when nothing consumes the current event.

I verified the load-bearing safety invariant directly: within a synchronous drain pass, this.callbacks must not be mutated except by the loop's own Finished splice. Confirmed that subscribe() only ever does process.nextTick(this.consume) — never a synchronous re-entry — and that onConsumedEvent (the clock-advance callback) doesn't subscribe. So new consumers can only appear on a later tick, exactly as the comment claims. The splice-at-i-then-return-and-restart pattern is correct: no callback is skipped across the index shift.

Two details I checked specifically:

  • The null sentinel can't spin the loop: consumeOne returns currentEvent !== null, so a consumed end-of-events sentinel (which real consumers return NotConsumed for anyway) terminates the drain. The defensive guard against a pathological callback consuming null is a nice belt-and-suspenders.
  • notifyConsumedEvent (clock advance) ordering is preserved — it still fires once per consumed event, in the same order; it just happens within one tick now instead of spread across N. Behaviorally identical for the deterministic-clock machinery.

The scheduleWhenIdlesetTimeout(0) is correctly left as a macrotask — the added comment documenting why (cross-VM resolve→VM-body→subscribe chain needs the macrotask boundary; queueMicrotask empirically breaks hook/sleep Promise.race with CorruptedEventLogError) is exactly the kind of tribal knowledge that belongs in the code.

Built @workflow/core, full suite green (1237), including events-consumer.test.ts, workflow.test.ts (79), and async-deserialization-ordering.test.ts. CI is mid-run; nothing failing that's attributable to this. LGTM.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

CI + review triage (commit 5039d8278)

Review comments: none to address. The only review is from copilot-pull-request-reviewer, whose body is "Copilot was unable to review this pull request because the user who requested the review has reached their quota limit." — no actual review content. Zero inline comments; all issue comments are bots (changeset/vercel/benchmark/e2e-results).

Windows Unit failure — REGRESSION (now fixed by revert). The previous commit (b9c9e192) failed Unit Tests (windows-latest) with a real CorruptedEventLogError / ReplayDivergenceError on a step_started event in world-testing's inline-batches-debug (3×5 parallel steps), originating at EventsConsumer.onUnconsumedEvent. main is green on that same job at the identical base SHA, and the test has shipped green for ~6 weeks — so this was introduced by the synchronous consume-drain, not a pre-existing flake. Root cause and the (reverted) fix are in the PR description. After the revert, packages/core unit suite is 1236/1236 green and inline-batches-debug passes serially.

E2E Local Dev (nextjs-turbopack, stable lazyDiscovery enabled) failure — unrelated, pre-existing flake. It failed on packages/core/e2e/dev.test.ts > should include steps discovered from workflow imports:

Timed out after 25000ms waiting for manifest.json to drop discoveredViaWorkflowStep after cleanup

This is a dev-server HMR / lazy-discovery manifest-cleanup test with no connection to the consume loop, replay, or scheduleWhenIdle. Since this branch now carries only a comment change, it cannot be the cause. ("E2E Required Check" failing in 2s is just the aggregate gate over that dev-test failure.) A re-run on the reverted branch should clear or confirm it as the shared flake.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Re-validation: revert was premature → optimization restored (commit 410034e15)

The earlier revert to a comment-only change rested on a singleinline-batches-debug failure on the windows-latest Unit job. I re-validated that empirically and it does not survive scrutiny — it's a pre-existing flake in that test on Windows, not a regression from the consume-drain:

SignalOptimizationUnmodified main
Local 8-way stress (80 runs each)4/80 (5.0%)7/80 (8.75%)
Historical windows-latest Unit flake rate~13% (10/76)
Fresh Windows CI Unit job (real job, not fast-pathed)4/4 pass4/4 pass
Isolated low-load40/40 pass

Run IDs (fresh Windows CI): opt = 27739171715, 27739454028, 27739455535, 27739457404; main = 27739493993, 27739495175, 27739497219, 27739498448. The exact Windows timeout reproduces on bare main at 4a5a23088 (run 27474356210), and the failure mode on both arms is a self-healing replay-divergence retry that times out — not a thrown CorruptedEventLogError.

The restored events-consumer.ts + test are byte-for-byte identical to the original optimization commit; scheduleWhenIdle's load-bearing setTimeout(0) is kept (with the explanatory comment). Core Unit suite: 1237 passed, 0 failed.

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #2504. (backport job run)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pranaygp@TooTallNate@VaguelySerious