Skip to content

Commit

Permalink
worker: use _writev in internal communication
Browse files Browse the repository at this point in the history
PR-URL: #33454
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
addaleax authored and codebytere committed Jul 6, 2020
1 parent 8803d7e commit c502384
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ port.on('message', (message) => {
CJSLoader.Module.runMain(filename);
}
} else if (message.type === STDIO_PAYLOAD) {
const { stream, chunk, encoding } = message;
process[stream].push(chunk, encoding);
const { stream, chunks } = message;
for (const { chunk, encoding } of chunks)
process[stream].push(chunk, encoding);
} else {
assert(
message.type === STDIO_WANTS_MORE_DATA,
Expand Down
7 changes: 5 additions & 2 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ class Worker extends EventEmitter {
return this[kOnErrorMessage](message.error);
case messageTypes.STDIO_PAYLOAD:
{
const { stream, chunk, encoding } = message;
return this[kParentSideStdio][stream].push(chunk, encoding);
const { stream, chunks } = message;
const readable = this[kParentSideStdio][stream];
for (const { chunk, encoding } of chunks)
readable.push(chunk, encoding);
return;
}
case messageTypes.STDIO_WANTS_MORE_DATA:
{
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/worker/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,11 @@ class WritableWorkerStdio extends Writable {
this[kWritableCallbacks] = [];
}

_write(chunk, encoding, cb) {
_writev(chunks, cb) {
this[kPort].postMessage({
type: messageTypes.STDIO_PAYLOAD,
stream: this[kName],
chunk,
encoding
chunks: chunks.map(({ chunk, encoding }) => ({ chunk, encoding }))
});
this[kWritableCallbacks].push(cb);
if (this[kPort][kWaitingStreams]++ === 0)
Expand All @@ -222,7 +221,7 @@ class WritableWorkerStdio extends Writable {
this[kPort].postMessage({
type: messageTypes.STDIO_PAYLOAD,
stream: this[kName],
chunk: null
chunks: [ { chunk: null, encoding: '' } ]
});
cb();
}
Expand Down

0 comments on commit c502384

Please sign in to comment.