-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
worker.postMessage performance #38780
Copy link
Copy link
Closed
Labels
performanceIssues and PRs related to the performance of Node.js.Issues and PRs related to the performance of Node.js.questionIssues asking questions about Node.js.Issues asking questions about Node.js.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
Description
Activity
Metadata
Metadata
Assignees
Labels
performanceIssues and PRs related to the performance of Node.js.Issues and PRs related to the performance of Node.js.questionIssues asking questions about Node.js.Issues asking questions about Node.js.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
I'm using
worker.postMessage(myString)to send data to my worker. However, I'm getting significant performance overhead frompostMessage. I'm spending 16% of my total cpu time here. The strings are usually quite short but can be up to 256 chars.Where does the overhead of
postMessagemostly come from and is there ways to improve it? I might be intersted in trying to improve it if someone could point me in the right direction.I've been consdering using a
SharedArrayBufferand writing the strings into the buffer and thenAtomics.wait/notify, However, that feels wrong as it basically just re-implements whatpostMessagecould/should be doing anyway. IsMessageChannelfaster?