diff options
author | Matteo Collina <hello@matteocollina.com> | 2019-07-24 15:56:13 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-07-26 21:58:09 -0700 |
commit | 147b9d9792fe5772b554f4be77305805f361a42d (patch) | |
tree | 7cd4d56cc063c8efcda2a7cd57778fd68eb3d75e /lib/_stream_readable.js | |
parent | db1c4a7592a896053a8f791d7cc38a6de5c4a059 (diff) | |
download | android-node-v8-147b9d9792fe5772b554f4be77305805f361a42d.tar.gz android-node-v8-147b9d9792fe5772b554f4be77305805f361a42d.tar.bz2 android-node-v8-147b9d9792fe5772b554f4be77305805f361a42d.zip |
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: https://github.com/nodejs/node/pull/28842
Fixes: https://github.com/nodejs/node/issues/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>
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r-- | lib/_stream_readable.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 5b73646db8..754e45da64 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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 since V8 7.3. + !(chunk instanceof Buffer)) { chunk = Stream._uint8ArrayToBuffer(chunk); } @@ -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); + } const state = this._readableState; const nOrig = n; |