Title: http: avoid dictionary-mode objects in responses by mcollina · Pull Request #66420 · nodejs/node · GitHub
Open Graph Title: http: avoid dictionary-mode objects in responses by mcollina · Pull Request #66420 · nodejs/node
X Title: http: avoid dictionary-mode objects in responses by mcollina · Pull Request #66420 · nodejs/node
Description: 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, for runtime-miss stores (the profile shows StoreIC::Store, Factory::NewStoreHandler and TieringManager::NotifyICChanged in steady state) and for dictionary lookups on every header access, including the for...in in _storeHeader(). This PR uses a fast-mode object with an empty null-prototype chain for the headers (same keys, same enumeration, no inherited properties), and presets the listener table with the common events, as Readable/Writable already do. Hello-world server (res.setHeader('Content-Type', ...) + res.end('Hello World')), server pinned to one core, wrk -t2 -c50 on two other physical cores, 4 interleaved rounds: req/s user µs/req sys µs/req alloc B/req main 40.9k 15.0 9.4 4374 this PR 50.0k 11.3 8.7 3905 The _events preset accounts for ~2% of that; the header container for the rest. With 8 request headers and a handler that reads two of them: 36.2k → 43.2k req/s. Responses are byte-identical. How much the dictionary-mode container costs depends on the response pattern (same harness, 2 rounds each): handler main this PR setHeader('Content-Type') + end(body) 41.7–42.4k 51.3–51.8k setHeader('Content-Type') + setHeader('Content-Length') + end(body) 47.1–49.6k 50.0–51.7k writeHead(200, { ... }) + end(body) (no setHeader(), benchmark/fixtures "normal") 46.1–50.0k 50.2–50.9k The existing benchmark/http fixtures either set Content-Length through setHeader() or pass every header to writeHead(), so they only show the smaller gains. The second commit adds a setHeaderImplicit case to http/set-header.js (res.setHeader('Content-Type', ...) + res.end(body), framing left to end()). benchmark/compare.js --runs 10 --filter set-header http: confidence improvement accuracy (*) (**) (***) http/set-header.js duration=5 res='normal' benchmarker='wrk' 2.53 % ±4.03% ±5.61% ±7.86% http/set-header.js duration=5 res='setHeader' benchmarker='wrk' ** 6.13 % ±4.03% ±5.55% ±7.61% http/set-header.js duration=5 res='setHeaderImplicit' benchmarker='wrk' *** 16.46 % ±5.10% ±7.06% ±9.78% http/set-header.js duration=5 res='setHeaderWH' benchmarker='wrk' 4.78 % ±5.76% ±7.89% ±10.75% simple.js, headers.js and incoming_headers.js are unchanged within noise. —- Ai generated, humanly reviewed.
Open Graph Description: 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 mod...
X Description: 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 mod...
Opengraph URL: https://github.com/nodejs/node/pull/66420
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:40b02e51-01bf-e586-586f-42dd05932220 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A15A:2A9C77:4DDAC:692BF:6AED62A4 |
| html-safe-nonce | c9b79b9416186b31e62cb5e054d40aed8982597c97f6885b68e393f40036dc36 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTVBOjJBOUM3Nzo0RERBQzo2OTJCRjo2QUVENjJBNCIsInZpc2l0b3JfaWQiOiIzNTg0MTU4MDc0MzkxMDYxMTU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e157b1b3cf9189cd59eec757ae121eadcff4e4965d87fa5198e3497054ce3aeb |
| hovercard-subject-tag | pull_request:4694408962 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/66420/files |
| twitter:image | https://avatars.githubusercontent.com/u/52195?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/52195?s=400&v=4 |
| og:image:alt | 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 mod... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width