Merge pull request 'perf(app): skip awaiting the boot in app.fetch once it has finished' (#178) from perf/fetch-skip-boot-await into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 20s
CI / build (push) Successful in 29s
CI / runtimes (edge) (push) Successful in 22s
CI / runtimes (deno) (push) Successful in 33s
Promote → GitHub / push-github (push) Successful in 6s
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 20s
CI / build (push) Successful in 29s
CI / runtimes (edge) (push) Successful in 22s
CI / runtimes (deno) (push) Successful in 33s
Promote → GitHub / push-github (push) Successful in 6s
This commit was merged in pull request #178.
This commit is contained in:
commit
1935e8e047
2 files changed
+15
-7
No files matched your search
@@ -317,6 +317,11 @@ npm treats versions as semver and semver forbids leading zeros.
|
|||||||
read, added for the incremental `413`, had cut a Bun JSON `POST` by more than half. Behaviour is
|
read, added for the incremental `413`, had cut a Bun JSON `POST` by more than half. Behaviour is
|
||||||
unchanged: the same `413`s, and `set-cookie` arrays still reach the client one line per cookie.
|
unchanged: the same `413`s, and `set-cookie` arrays still reach the client one line per cookie.
|
||||||
|
|
||||||
|
- **`app.fetch` stops awaiting the boot once it has finished.** Since the health probes, every
|
||||||
|
request went through an `async` wrapper around the memoized boot, which cost a promise and
|
||||||
|
microtask hops even after the app was up. The first request still waits for the boot, and a boot
|
||||||
|
that failed still fails every request.
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- **The `Headers` type** (D19). Import `RequestHeaders` instead: same type, a name that does not
|
- **The `Headers` type** (D19). Import `RequestHeaders` instead: same type, a name that does not
|
||||||
|
|||||||
+10
-7
@@ -1810,6 +1810,15 @@ function buildAppFetch(
|
|||||||
): (request: Request) => Promise<Response> {
|
): (request: Request) => Promise<Response> {
|
||||||
let handler: ((request: Request) => Promise<Response>) | undefined;
|
let handler: ((request: Request) => Promise<Response>) | undefined;
|
||||||
|
|
||||||
|
// Awaits the boot, then builds the table. Only until the first request has done so: a built table
|
||||||
|
// means the boot succeeded, and awaiting a settled boot again costs every request a promise and
|
||||||
|
// microtask hops (about 6% of a small request on Deno).
|
||||||
|
const firstRequest = async (request: Request): Promise<Response> => {
|
||||||
|
await ensureBooted(); // idempotent: no-op once any of fetch/upgrade/listen has booted
|
||||||
|
handler ??= buildFetch(getRoutes, fetchOpts);
|
||||||
|
return handler(request);
|
||||||
|
};
|
||||||
|
|
||||||
return async (request: Request): Promise<Response> => {
|
return async (request: Request): Promise<Response> => {
|
||||||
// Before the boot, or `/__ready__` could never say `booting`: it would wait for the boot to end.
|
// Before the boot, or `/__ready__` could never say `booting`: it would wait for the boot to end.
|
||||||
// The boot is still started, not awaited: on the edge, or under a bare `Deno.serve(app.fetch)`,
|
// The boot is still started, not awaited: on the edge, or under a bare `Deno.serve(app.fetch)`,
|
||||||
@@ -1822,13 +1831,7 @@ function buildAppFetch(
|
|||||||
return probe;
|
return probe;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ensureBooted(); // idempotent: no-op once any of fetch/upgrade/listen has booted
|
return handler ? handler(request) : firstRequest(request);
|
||||||
|
|
||||||
if (!handler) {
|
|
||||||
handler = buildFetch(getRoutes, fetchOpts);
|
|
||||||
}
|
|
||||||
|
|
||||||
return handler(request);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user