From 6f03b564ec53d889b775d8e1d29c9c94d9097bec Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Fri, 2 Jun 2017 16:51:05 +0200 Subject: [PATCH] streams: Ensure that instanceof fast-path is hit. With the new Ignition+TurboFan pipeline, the instanceof fast-path can be missed if the right-hand side needs a TDZ check, i.e. is const declared on a surrounding scope. This doesn't apply to Node 8 at this point, where it's at V8 5.8, but it applies as soon as V8 5.9 rolls. There's work going on in Ignition (and TurboFan) to optimize those TDZ checks properly, but those changes will land in V8 6.1, so might not end up in Node 8. One way to work-around this in Node core for now is to use var instead of const for those right-hand sides for instanceof for now, especially Buffer in case of streams. This is not beautiful, but proper ducktape. Improves readable-bigread.js by ~23% with Node LKGR. --- lib/_stream_readable.js | 4 +++- lib/_stream_wrap.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index d6af8589f3bc85..afa53bc93fb34b 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -5,7 +5,9 @@ Readable.ReadableState = ReadableState; const EE = require('events'); const Stream = require('stream'); -const Buffer = require('buffer').Buffer; +// TODO(bmeurer): Change this back to const once hole checks are +// properly optimized away early in Ignition+TurboFan. +var Buffer = require('buffer').Buffer; const util = require('util'); const debug = util.debuglog('stream'); const BufferList = require('internal/streams/BufferList'); diff --git a/lib/_stream_wrap.js b/lib/_stream_wrap.js index fbc32965980e96..f3f79ebf05ba5f 100644 --- a/lib/_stream_wrap.js +++ b/lib/_stream_wrap.js @@ -4,7 +4,9 @@ const assert = require('assert'); const util = require('util'); const Socket = require('net').Socket; const JSStream = process.binding('js_stream').JSStream; -const Buffer = require('buffer').Buffer; +// TODO(bmeurer): Change this back to const once hole checks are +// properly optimized away early in Ignition+TurboFan. +var Buffer = require('buffer').Buffer; const uv = process.binding('uv'); const debug = util.debuglog('stream_wrap');