From 55f9c85a0511adbb110e1521015244d8686c548b Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Fri, 2 Jun 2017 16:51:05 +0200 Subject: [PATCH] stream: 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. PR-URL: https://github.com/nodejs/node/pull/13403 Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Calvin Metcalf --- 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 4ba224cd5a..900f42e171 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -26,7 +26,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 2ddf15069e..25a77b8c4a 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');