diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-10-21 09:34:00 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-10-24 10:57:42 +0300 |
commit | 1365f657b51d31044cca54c3152d3940a4bd9dc3 (patch) | |
tree | 4772c2b484555de0a0368b35ebf889ff23d154c2 /lib/internal/child_process.js | |
parent | bb79e768e5ab150f2075780734005783d53eb3ca (diff) |
src: improve StreamBase read throughput
Improve performance by providing JS with the raw ingridients
for the read data, i.e. an `ArrayBuffer` + offset + length
fields, instead of creating `Buffer` instances in C++ land.
PR-URL: https://github.com/nodejs/node/pull/23797
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/child_process.js')
-rw-r--r-- | lib/internal/child_process.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index e6cdde56c1f..74d69de0dcd 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -22,7 +22,12 @@ const util = require('util'); const assert = require('assert'); const { Process } = internalBinding('process_wrap'); -const { WriteWrap } = internalBinding('stream_wrap'); +const { + WriteWrap, + kReadBytesOrError, + kArrayBufferOffset, + streamBaseState +} = internalBinding('stream_wrap'); const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap'); const { TCP } = internalBinding('tcp_wrap'); const { TTY } = internalBinding('tty_wrap'); @@ -486,11 +491,13 @@ function setupChannel(target, channel) { var pendingHandle = null; channel.buffering = false; channel.pendingHandle = null; - channel.onread = function(nread, pool) { + channel.onread = function(arrayBuffer) { const recvHandle = channel.pendingHandle; channel.pendingHandle = null; - // TODO(bnoordhuis) Check that nread > 0. - if (pool) { + if (arrayBuffer) { + const nread = streamBaseState[kReadBytesOrError]; + const offset = streamBaseState[kArrayBufferOffset]; + const pool = new Uint8Array(arrayBuffer, offset, nread); if (recvHandle) pendingHandle = recvHandle; |