Skip to content

worker.postMessage performance #38780

Closed
Closed
@ronag

Description

@ronag

I'm using worker.postMessage(myString) to send data to my worker. However, I'm getting significant performance overhead from postMessage. 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 postMessage mostly 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 SharedArrayBuffer and writing the strings into the buffer and then Atomics.wait/notify, However, that feels wrong as it basically just re-implements what postMessage could/should be doing anyway. Is MessageChannel faster?

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceIssues and PRs related to the performance of Node.js.questionIssues that look for answers.workerIssues and PRs related to Worker support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions