Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: resolve perf regression introduced by V8 7.3 #28842

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
} else if (state.objectMode || chunk && chunk.length > 0) {
if (typeof chunk !== 'string' &&
!state.objectMode &&
Object.getPrototypeOf(chunk) !== Buffer.prototype) {
// Do not use Object.getPrototypeOf as it is slower.
mcollina marked this conversation as resolved.
Show resolved Hide resolved
!(chunk instanceof Buffer)) {
mcollina marked this conversation as resolved.
Show resolved Hide resolved
chunk = Stream._uint8ArrayToBuffer(chunk);
}

Expand Down Expand Up @@ -399,7 +400,13 @@ function howMuchToRead(n, state) {
// You can override either this method, or the async _read(n) below.
Readable.prototype.read = function(n) {
debug('read', n);
n = parseInt(n, 10);
// Same as parseInt(undefined, 10), however V8 7.3 performance regressed
// in this scenario, so we are doing it manually.
if (n === undefined) {
n = NaN;
} else if (!Number.isInteger(n)) {
n = parseInt(n, 10);
mcollina marked this conversation as resolved.
Show resolved Hide resolved
}
const state = this._readableState;
const nOrig = n;

Expand Down
3 changes: 2 additions & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ Writable.prototype.write = function(chunk, encoding, cb) {
var ret = false;
const isBuf = !state.objectMode && Stream._isUint8Array(chunk);

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

Expand Down