Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf071a0

Browse filesBrowse files
mcollinatargos
authored andcommitted
stream: resolve perf regression introduced by V8 7.3
This commit contains two fixes: 1. use instanceof instead of Object.getPrototypeOf, as checking an object prototype with Object.getPrototypeOf is slower than an instanceof check. 2. avoid parseInt(undefined, 10) to get NaN as it regressed. PR-URL: #28842 Fixes: #28586 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent e6b3bfe commit cf071a0
Copy full SHA for cf071a0

File tree

Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed
Open diff view settings
Collapse file

‎lib/_stream_readable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_readable.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
250250
} else if (state.objectMode || chunk && chunk.length > 0) {
251251
if (typeof chunk !== 'string' &&
252252
!state.objectMode &&
253-
Object.getPrototypeOf(chunk) !== Buffer.prototype) {
253+
// Do not use Object.getPrototypeOf as it is slower since V8 7.3.
254+
!(chunk instanceof Buffer)) {
254255
chunk = Stream._uint8ArrayToBuffer(chunk);
255256
}
256257

@@ -393,7 +394,13 @@ function howMuchToRead(n, state) {
393394
// You can override either this method, or the async _read(n) below.
394395
Readable.prototype.read = function(n) {
395396
debug('read', n);
396-
n = parseInt(n, 10);
397+
// Same as parseInt(undefined, 10), however V8 7.3 performance regressed
398+
// in this scenario, so we are doing it manually.
399+
if (n === undefined) {
400+
n = NaN;
401+
} else if (!Number.isInteger(n)) {
402+
n = parseInt(n, 10);
403+
}
397404
const state = this._readableState;
398405
const nOrig = n;
399406

Collapse file

‎lib/_stream_writable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_writable.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ Writable.prototype.write = function(chunk, encoding, cb) {
277277
var ret = false;
278278
const isBuf = !state.objectMode && Stream._isUint8Array(chunk);
279279

280-
if (isBuf && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
280+
// Do not use Object.getPrototypeOf as it is slower since V8 7.3.
281+
if (isBuf && !(chunk instanceof Buffer)) {
281282
chunk = Stream._uint8ArrayToBuffer(chunk);
282283
}
283284

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.