lib: revert primordials in a hot path · nodejs/node@ee9e2a2 · GitHub
Skip to content

Commit ee9e2a2

Browse files
aduh95mcollina
authored andcommitted
lib: revert primordials in a hot path
Evidence has shown that use of primordials have sometimes an impact of performance. This commit reverts the changes who are most likely to be responsible for performance regression in the HTTP response path. PR-URL: #38248 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 4e9212b commit ee9e2a2

20 files changed

Lines changed: 182 additions & 222 deletions

lib/_http_common.js

Lines changed: 2 additions & 4 deletions

lib/_http_incoming.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
'use strict';
2323

2424
const {
25-
ArrayPrototypePush,
26-
FunctionPrototypeCall,
2725
ObjectDefineProperty,
2826
ObjectSetPrototypeOf,
2927
StringPrototypeCharCodeAt,
@@ -59,7 +57,7 @@ function IncomingMessage(socket) {
5957
};
6058
}
6159

62-
FunctionPrototypeCall(Readable, this, streamOptions);
60+
Readable.call(this, streamOptions);
6361

6462
this._readableState.readingMore = true;
6563

@@ -350,7 +348,7 @@ function _addHeaderLine(field, value, dest) {
350348
} else if (flag === 1) {
351349
// Array header -- only Set-Cookie at the moment
352350
if (dest['set-cookie'] !== undefined) {
353-
ArrayPrototypePush(dest['set-cookie'], value);
351+
dest['set-cookie'].push(value);
354352
} else {
355353
dest['set-cookie'] = [value];
356354
}

lib/_http_outgoing.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@
2424
const {
2525
Array,
2626
ArrayIsArray,
27-
ArrayPrototypeForEach,
2827
ArrayPrototypeJoin,
29-
ArrayPrototypePush,
30-
ArrayPrototypeUnshift,
31-
FunctionPrototype,
32-
FunctionPrototypeBind,
33-
FunctionPrototypeCall,
3428
MathFloor,
3529
NumberPrototypeToString,
3630
ObjectCreate,
@@ -88,7 +82,7 @@ const { CRLF } = common;
8882

8983
const kCorked = Symbol('corked');
9084

91-
const nop = FunctionPrototype;
85+
const nop = () => {};
9286

9387
const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
9488
const RE_TE_CHUNKED = common.chunkExpression;
@@ -101,7 +95,7 @@ function isCookieField(s) {
10195
}
10296

10397
function OutgoingMessage() {
104-
FunctionPrototypeCall(Stream, this);
98+
Stream.call(this);
10599

106100
// Queue that holds all currently pending data, until the response will be
107101
// assigned to the socket (until it will its turn in the HTTP pipeline).
@@ -331,7 +325,7 @@ OutgoingMessage.prototype._send = function _send(data, encoding, callback) {
331325
data = this._header + data;
332326
} else {
333327
const header = this._header;
334-
ArrayPrototypeUnshift(this.outputData, {
328+
this.outputData.unshift({
335329
data: header,
336330
encoding: 'latin1',
337331
callback: null
@@ -368,7 +362,7 @@ function _writeRaw(data, encoding, callback) {
368362
return conn.write(data, encoding, callback);
369363
}
370364
// Buffer, as long as we're not destroyed.
371-
ArrayPrototypePush(this.outputData, { data, encoding, callback });
365+
this.outputData.push({ data, encoding, callback });
372366
this.outputSize += data.length;
373367
this._onPendingData(data.length);
374368
return this.outputSize < HIGH_WATER_MARK;
@@ -397,9 +391,10 @@ function _storeHeader(firstLine, headers) {
397391
}
398392
} else if (ArrayIsArray(headers)) {
399393
if (headers.length && ArrayIsArray(headers[0])) {
400-
ArrayPrototypeForEach(headers, (entry) =>
401-
processHeader(this, state, entry[0], entry[1], true)
402-
);
394+
for (let i = 0; i < headers.length; i++) {
395+
const entry = headers[i];
396+
processHeader(this, state, entry[0], entry[1], true);
397+
}
403398
} else {
404399
if (headers.length % 2 !== 0) {
405400
throw new ERR_INVALID_ARG_VALUE('headers', headers);
@@ -877,7 +872,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
877872
if (typeof callback === 'function')
878873
this.once('finish', callback);
879874

880-
const finish = FunctionPrototypeBind(onFinish, undefined, this);
875+
const finish = onFinish.bind(undefined, this);
881876

882877
if (this._hasBody && this.chunkedEncoding) {
883878
this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish);

lib/_http_server.js

Lines changed: 41 additions & 47 deletions

0 commit comments

Comments
 (0)