Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: use _writev in internal communication #33454

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,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 @@ -243,8 +243,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