Skip to content

Commit 6f03b56

Browse files
committed
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.
1 parent 55f5301 commit 6f03b56

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/_stream_readable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Readable.ReadableState = ReadableState;
55

66
const EE = require('events');
77
const Stream = require('stream');
8-
const Buffer = require('buffer').Buffer;
8+
// TODO(bmeurer): Change this back to const once hole checks are
9+
// properly optimized away early in Ignition+TurboFan.
10+
var Buffer = require('buffer').Buffer;
911
const util = require('util');
1012
const debug = util.debuglog('stream');
1113
const BufferList = require('internal/streams/BufferList');

lib/_stream_wrap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const assert = require('assert');
44
const util = require('util');
55
const Socket = require('net').Socket;
66
const JSStream = process.binding('js_stream').JSStream;
7-
const Buffer = require('buffer').Buffer;
7+
// TODO(bmeurer): Change this back to const once hole checks are
8+
// properly optimized away early in Ignition+TurboFan.
9+
var Buffer = require('buffer').Buffer;
810
const uv = process.binding('uv');
911
const debug = util.debuglog('stream_wrap');
1012

0 commit comments

Comments
 (0)