Browse Source

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 <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Calvin Metcalf <calvin.metcalf@gmail.com>
v6
Benedikt Meurer 8 years ago
committed by Anna Henningsen
parent
commit
55f9c85a05
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 4
      lib/_stream_readable.js
  2. 4
      lib/_stream_wrap.js

4
lib/_stream_readable.js

@ -26,7 +26,9 @@ Readable.ReadableState = ReadableState;
const EE = require('events'); const EE = require('events');
const Stream = require('stream'); 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 util = require('util');
const debug = util.debuglog('stream'); const debug = util.debuglog('stream');
const BufferList = require('internal/streams/BufferList'); const BufferList = require('internal/streams/BufferList');

4
lib/_stream_wrap.js

@ -4,7 +4,9 @@ const assert = require('assert');
const util = require('util'); const util = require('util');
const Socket = require('net').Socket; const Socket = require('net').Socket;
const JSStream = process.binding('js_stream').JSStream; 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 uv = process.binding('uv');
const debug = util.debuglog('stream_wrap'); const debug = util.debuglog('stream_wrap');

Loading…
Cancel
Save