http: avoid dictionary-mode objects in responses · nodejs/node@6487d36 · GitHub
Skip to content

Commit 6487d36

Browse files
mcollinaaduh95
authored andcommitted
http: avoid dictionary-mode objects in responses
`setHeader()` stored headers in a `{ __proto__: null }` literal and `OutgoingMessage` let EventEmitter create the same literal for its listener table. V8 creates null-prototype literals in dictionary mode, so every response paid for a hash table allocation on the first `setHeader()`/`on()` call and for dictionary lookups on every header access, including the `for...in` in `_storeHeader()`. Use a fast-mode object with an empty null-prototype chain for the headers, and preset the listener table with the common events, as streams already do. Hello-world server (`res.setHeader()` + `res.end()`), one core: 40.9k -> 50.0k req/s (+22%); CPU 24.4 -> 20.0 us/req; 4374 -> 3905 B of young-gen allocation per request. Responses are byte-identical. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #66420 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent bb3d33e commit 6487d36

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎lib/_http_outgoing.js‎

Lines changed: 22 additions & 1 deletion

0 commit comments

Comments
 (0)