Deep graphs: O(n²) → O(n), plus a boot warning when they're suspiciously deep #2

Merged
chrnx merged 3 commits from fix/pipeline-context-on2 into develop 2026-07-18 00:35:29 +00:00
Owner

Three commits on this branch:

  • perf(pipeline) — runSteps rebuilt the whole request context on every step ({ ...ctx, ...out }), O(n²) in the number of steps. Merged in place with Object.assign → O(n). Measured 2.5× at 100 chained steps (251µs → 100µs/req); per-step cost goes from superlinear to a flat ~0.5µs/step. Adds a regression guard.
  • feat(app) — boot-time warning when a route's dependency chain resolves to >20 steps (a modeling smell, not a perf limit — a warning, not an error). Silenceable/tunable via createApp({ warnGraphDepth }).
  • test(bench) — bind bench servers to 0.0.0.0 for two-machine runs; add step-depth (scale-*) and Bun/Deno bench servers.

Full suite green (326 tests). Verified on real Bun 1.3.14 and Deno 2.9.3.

Three commits on this branch: - **perf(pipeline)** — `runSteps` rebuilt the whole request context on every step (`{ ...ctx, ...out }`), O(n²) in the number of steps. Merged in place with `Object.assign` → O(n). Measured **2.5× at 100 chained steps** (251µs → 100µs/req); per-step cost goes from superlinear to a flat ~0.5µs/step. Adds a regression guard. - **feat(app)** — boot-time warning when a route's dependency chain resolves to >20 steps (a modeling smell, not a perf limit — a warning, not an error). Silenceable/tunable via `createApp({ warnGraphDepth })`. - **test(bench)** — bind bench servers to `0.0.0.0` for two-machine runs; add step-depth (`scale-*`) and Bun/Deno bench servers. Full suite green (**326 tests**). Verified on real **Bun 1.3.14** and **Deno 2.9.3**.
chrnx added 3 commits 2026-07-18 00:35:09 +00:00
runSteps rebuilt the whole request context every step with { ...context, ...output }, so an N-step route paid 1+2+...+N = O(N^2) property copies plus N throwaway objects. At 100 chained steps that measured ~250us/req vs ~100us after the fix (2.5x throughput); per-step cost drops from superlinear to a flat ~0.5us/step.

Mutate one accumulator in place with Object.assign -- O(N). The returned context is now the same object every step observes. Adds a regression guard that fails if a per-step copy is reintroduced; full suite green (322 tests).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
A route whose need-closure resolves to more than 20 steps is almost always a modeling smell -- a step doing too much, or work that belongs in a provider. Per-request cost is linear, so this is a design nudge, not a perf guard (and a warning, not an error).

Tunable and silenceable via createApp({ warnGraphDepth }): a number sets the threshold, false quiets it. Default 20.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Fastify and the Nest adapters bound 127.0.0.1, unreachable from a separate load generator; bind 0.0.0.0 so two-machine benchmarks work.

Adds scale-{green-tea,express} (step-vs-middleware depth sweeps that surfaced the O(n^2)) and green-tea-{bun,deno} (the same app served via serveBun/serveDeno, to benchmark across runtimes).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx merged commit 91fe8f8aff into develop 2026-07-18 00:35:29 +00:00
Sign in to join this conversation.