perf(http): trim per-request work on the Node path
Profiling the validate (POST) bench route against4d1639fshowed the loss since then spread over several small costs on the Node request path rather than one regression. This removes the ones that do not change behaviour: - readBody reads with data/end/error/close listeners instead of `for await`, whose async iterator costs a promise and a microtask per chunk. It keeps the iterator's semantics: the running total enforces the limit, an over-limit body destroys the request as leaving the loop did, an error or a close before `end` rejects (the latter with ERR_STREAM_PREMATURE_CLOSE), and the declared-length 413 is still a rejection rather than a synchronous throw. A single chunk is returned without Buffer.concat. - writeResult is no longer async. A buffered response without compression is written synchronously and returns nothing to await; only a stream or a compressed body returns a promise, which serve awaits, so a failure still reaches failSafe. The compression request object is not built when compression is off. - declaresOverLimit compares the number first and runs its /^\d+$/ shape test only when the length is over the limit. The `serve().catch(failSafe)` wrapper stays: it is the #108 guarantee, and handle() is asynchronous, so there is no synchronous path to skip. Local A/B against74faa55(5 s x 4 rounds, macOS, indicative only): validate (POST) +4.6%. test/read-body.test.ts pins readBody's semantics: joining, empty body, 413 with destroy, declared-length 413, stream error and premature close. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
5 files changed
+133
-29
No files matched your search
@@ -272,6 +272,13 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
introspection routes (`devGraph`, `devOpenapi`) now sit before remote routes in that table, so
|
||||
in the one case where a teapot exports the same path at the same specificity, the dev route wins.
|
||||
|
||||
- **The Node request path does less per request.** A JSON `POST` reads its body with stream
|
||||
listeners instead of `for await`, which cost a promise and a microtask per chunk; the response is
|
||||
written without an `async` wrapper when nothing needs awaiting, and without building the
|
||||
compression request when compression is off; the `content-length` limit check runs its shape test
|
||||
only for a body that would be refused. Behaviour is unchanged: the same `413`s, the same
|
||||
rejection when a client goes away mid-body.
|
||||
|
||||
### Deprecated
|
||||
|
||||
- **The `Headers` type** (D19). Import `RequestHeaders` instead: same type, a name that does not
|
||||
|
||||
Reference in new issue
Block a user