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

Returning an array from thread #15

Closed
dy opened this issue Apr 8, 2016 · 5 comments
Closed

Returning an array from thread #15

dy opened this issue Apr 8, 2016 · 5 comments

Comments

@dy
Copy link

dy commented Apr 8, 2016

Hi @andywer!

An issue actually related with audreyt/node-webworker-threads#99.
I tried both webworker-threads and threads libs to implement multithreading in nogl-shader-output, and both packages get very slow at returning an array from threads. It takes 800ms on my laptop to return 300×300 array from the thread.

Whether something I don’t know or is there a way to speed things up?

Thank you.

@andywer
Copy link
Owner

andywer commented Apr 8, 2016

Hey Deema!

Did you use https://github.com/andywer/threads.js#transferable-objects? Passing large arrays is by default very slow, since the whole array is copied when sending messages between the threads. But you can explicitly transfer the ownership of an array to the other thread when sending data to it (see link). This is much faster, but the sending thread cannot access the array anymore until the other thread gives the array ownership back.

@andywer
Copy link
Owner

andywer commented Apr 8, 2016

I forgot to ask: Are you working in a browser or a node.js setting?

@dy
Copy link
Author

dy commented Apr 8, 2016

@andywer in node. In browser it does not seem to be an issue.

@andywer
Copy link
Owner

andywer commented Apr 9, 2016

Yeah, my suggested approach was also browser-related... I don't have a Node.js solution by hand right now. The best I could come up with when googling it was this: audreyt/node-webworker-threads#58

But that issue seems quite dead...

@andywer
Copy link
Owner

andywer commented Apr 19, 2018

Closing for now.

This is a rather tough one. Might be easy to fix once node supports web workers (nodejs/node#13143).

@andywer andywer closed this as completed Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants