perf(app): skip awaiting the boot in app.fetch once it has finished #178

Merged
chrnx merged 1 commits from perf/fetch-skip-boot-await into develop 2026-10-29 03:06:36 +00:00
Owner

Since the health probes (#145), every app.fetch request went through trackHealth's async wrapper around the memoized boot. That costs a new promise and extra microtask hops per request, even with the app already booted and with health off.

What changed

buildAppFetch (src/app/index.ts): once the route table is built, a request goes straight to it.

  • Before the table exists, a request still awaits the boot and then builds the table.
  • A failed boot never builds the table, so it still rejects every request.
  • Health probes are still answered before the boot, as before.

Node is not touched: listen() does not go through app.fetch.

How it was found

The goal was to find Deno's remaining drift against 26.9.0-beta.2. I ran app.fetch in a loop on Deno with no server (param route) at each of the 53 develop merges since beta.2. Three steps showed up:

Merge Effect in the loop Status
radix router (cb123e3) about −5% net with few routes within the D4 gate, gains at 200 routes
health probes (1da6bf2) −6% this PR
cookies (50010da) −11% recovered by #175

Measured

  • In the loop (Mac): +3% to +6% on the param route.
  • Over HTTP: develop (068614e) → this branch on a Ryzen 3700X, docker node:22, 4 pinned cores. 15 cases including gzip, brotli and identity, 4 rounds. A/A noise band ±4%.
Runtime Result
Deno flat: −2.7% to +5.1%, every case overlapping
Bun +2% to +5%, non-overlapping on 8 of 15 cases (hello +3.8%, POST +4%, preflight +4.7%, 50 routes +3.1%)

Over HTTP the gain is smaller than in the loop, because the server's per-request cost dilutes it.

Not run: Node, which does not use this path.

Tests

  • npm test: 1210 passed.
  • npm audit: clean.
Since the health probes (#145), every `app.fetch` request went through `trackHealth`'s `async` wrapper around the memoized boot. That costs a new promise and extra microtask hops per request, even with the app already booted and with `health` off. ## What changed `buildAppFetch` (`src/app/index.ts`): once the route table is built, a request goes straight to it. - **Before the table exists**, a request still awaits the boot and then builds the table. - **A failed boot** never builds the table, so it still rejects every request. - **Health probes** are still answered before the boot, as before. Node is not touched: `listen()` does not go through `app.fetch`. ## How it was found The goal was to find Deno's remaining drift against 26.9.0-beta.2. I ran `app.fetch` in a loop on Deno with no server (param route) at each of the 53 develop merges since beta.2. Three steps showed up: | Merge | Effect in the loop | Status | | --- | --- | --- | | radix router (`cb123e3`) | about −5% net with few routes | within the D4 gate, gains at 200 routes | | health probes (`1da6bf2`) | −6% | this PR | | cookies (`50010da`) | −11% | recovered by #175 | ## Measured - **In the loop (Mac):** +3% to +6% on the param route. - **Over HTTP:** `develop (068614e) → this branch` on a Ryzen 3700X, docker `node:22`, 4 pinned cores. 15 cases including gzip, brotli and identity, 4 rounds. A/A noise band ±4%. | Runtime | Result | | --- | --- | | Deno | flat: −2.7% to +5.1%, every case overlapping | | Bun | +2% to +5%, non-overlapping on 8 of 15 cases (hello +3.8%, POST +4%, preflight +4.7%, 50 routes +3.1%) | Over HTTP the gain is smaller than in the loop, because the server's per-request cost dilutes it. Not run: Node, which does not use this path. ## Tests - `npm test`: 1210 passed. - `npm audit`: clean.
chrnx added 1 commit 2026-10-29 03:05:25 +00:00
perf(app): skip awaiting the boot in app.fetch once it has finished
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 21s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 23s
CI / runtimes (deno) (pull_request) Successful in 33s
d51ff3bee4
trackHealth wraps the memoized boot in an async function, so every
app.fetch request paid a new promise and microtask hops awaiting a boot
that had already settled. A built route table means the boot succeeded,
so the fetch handler now goes straight to it; only requests before the
table exists await the boot. A failed boot still rejects every request,
because the table is never built.

Measured in-process on Deno (app.fetch in a loop, param route): about
+3-6%.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx merged commit 1935e8e047 into develop 2026-10-29 03:06:36 +00:00
Sign in to join this conversation.