Skip to content

Commit af61c79

Browse files
committed
http: move invariant IncomingMessage defaults to the prototype
Fields the parser (or the client/server glue) assigns before user code can observe the message (httpVersion*, url, method, statusCode, statusMessage, upgrade) become prototype defaults instead of nine per-request own-property stores. Note: for messages that never get these fields assigned (bare IncomingMessage construction outside the parser path), they disappear from Object.keys()/spread results, though property reads are unchanged. Kept as a separate commit so it can be dropped independently if that tradeoff is unwanted. Together with the previous commit this measures +8.46% requests per CPU-second (p=2.2e-11, 15x600k-request interleaved samples) over the pre-series baseline. Assisted-by: Grok Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 43a9d71 commit af61c79

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

lib/_http_incoming.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ function IncomingMessage(socket) {
6565

6666
this.socket = socket;
6767

68-
this.httpVersionMajor = null;
69-
this.httpVersionMinor = null;
70-
this.httpVersion = null;
7168
this.complete = false;
7269
this[kHeaders] = null;
7370
this[kHeadersCount] = 0;
@@ -78,15 +75,6 @@ function IncomingMessage(socket) {
7875
this.joinDuplicateHeaders = false;
7976
this.aborted = false;
8077

81-
this.upgrade = null;
82-
83-
// request (server) only
84-
this.url = '';
85-
this.method = null;
86-
87-
// response (client) only
88-
this.statusCode = null;
89-
this.statusMessage = null;
9078
this.client = socket;
9179

9280
this._consuming = false;
@@ -98,6 +86,20 @@ function IncomingMessage(socket) {
9886
ObjectSetPrototypeOf(IncomingMessage.prototype, Readable.prototype);
9987
ObjectSetPrototypeOf(IncomingMessage, Readable);
10088

89+
// Fields the parser (or the client/server glue) assigns before user code
90+
// can observe the message live on the prototype as defaults instead of
91+
// being written per instance: ~9 fewer own-property stores per request.
92+
IncomingMessage.prototype.httpVersionMajor = null;
93+
IncomingMessage.prototype.httpVersionMinor = null;
94+
IncomingMessage.prototype.httpVersion = null;
95+
IncomingMessage.prototype.upgrade = null;
96+
// Request (server) only.
97+
IncomingMessage.prototype.url = '';
98+
IncomingMessage.prototype.method = null;
99+
// Response (client) only.
100+
IncomingMessage.prototype.statusCode = null;
101+
IncomingMessage.prototype.statusMessage = null;
102+
101103
ObjectDefineProperty(IncomingMessage.prototype, 'connection', {
102104
__proto__: null,
103105
get: function() {

0 commit comments

Comments
 (0)