Skip to content

Commit bf06534

Browse files
bmeureraddaleax
authored andcommitted
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: #13403 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Calvin Metcalf <[email protected]>
1 parent 12036a1 commit bf06534

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/_stream_readable.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ Readable.ReadableState = ReadableState;
2626

2727
const EE = require('events');
2828
const Stream = require('stream');
29-
const Buffer = require('buffer').Buffer;
29+
// TODO(bmeurer): Change this back to const once hole checks are
30+
// properly optimized away early in Ignition+TurboFan.
31+
var Buffer = require('buffer').Buffer;
3032
const util = require('util');
3133
const debug = util.debuglog('stream');
3234
const BufferList = require('internal/streams/BufferList');

lib/_stream_wrap.js

+3-1
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)