From 06869e5f01ff45bd9e02fdf01954ae8ee7deae72 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Fri, 30 Oct 2026 20:27:10 -0500 Subject: [PATCH] perf(graph): test a single provided token directly in the return-contract check A @Provider or @Step provides one token, so the check no longer goes through every() and its callback. On a 3-step pipeline the 4-round A/B against the freeze commit showed -4.6% on Deno and -3.2% on Bun, both outside the noise; with this change and 8 rounds every case overlaps. Signed-off-by: Diego Resendez --- src/app/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/index.ts b/src/app/index.ts index 9257586..3b12075 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -575,8 +575,7 @@ function emptyRegistry(): Registry { * so a plain step pays a type test rather than an extra microtask on the hot path. */ function keyedRunner(kind: string, name: string, provides: readonly string[], run: Runner): Runner { - const check = (output: unknown): unknown => { - if (output !== null && typeof output === 'object' && provides.every((token) => token in output)) return output; + const fail = (output: unknown): never => { const example = provides.map((token) => `${token}: `).join(', '); throw new TypeError( `${kind} '${name}' returned ${describeOutput(output)}, but it must return an object holding what it ` + @@ -584,6 +583,18 @@ function keyedRunner(kind: string, name: string, provides: readonly string[], ru ); }; + // A @Provider or @Step provides one token: test it directly rather than through `every` and its + // callback, which measured as a 3-4% drop on a 3-step pipeline under Deno and Bun. + const [only] = provides; + const check = + provides.length === 1 + ? (output: unknown): unknown => + output !== null && typeof output === 'object' && only! in output ? output : fail(output) + : (output: unknown): unknown => + output !== null && typeof output === 'object' && provides.every((token) => token in output) + ? output + : fail(output); + return (ctx) => { const output = run(ctx); return output instanceof Promise ? output.then(check) : check(output);