perf(graph): test a single provided token directly in the return-contract check
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 49s
CI / build (pull_request) Successful in 1m15s
CI / runtimes (deno) (pull_request) Successful in 1m3s
CI / runtimes (edge) (pull_request) Successful in 49s

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 <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-30 20:27:10 -05:00
1 parent c7f4a35008
commit 06869e5f01
1 file changed
+13 -2
+13 -2
View File
@@ -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}: <value>`).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);