audreyt / node-webworker-threads

Lightweight Web Worker API implementation with native threads
https://npmjs.org/package/webworker-threads
Other
2.3k stars 149 forks source link

difference of webworker-threads vs. natvie child process #146

Closed thisconnect closed 7 years ago

thisconnect commented 7 years ago

What is the difference https://nodejs.org/api/child_process.html ?

When would you use child process and when would you use webworker-threads?

audreyt commented 7 years ago

For the WebWorker API this module is compatible with https://www.npmjs.com/package/tiny-worker — perhaps try both, benchmark, and switch as needed?

davisjam commented 7 years ago

webworker-threads lets you offload computation using the WebWorker API, so you can write code against the WebWorker API and it will work in the browser or in Node. The Node child process module is Node-specific so your code wouldn't be portable.

You could support the WebWorker API using child processes instead of webworker-threads. webworker-threads has lower communication overhead and resource consumption than child processes would, but the tradeoff is that webworker-threads is (at the moment) a bit harder to program in. For example, require won't work in webworker-threads right now; see #113.

thisconnect commented 7 years ago

@davisjam thanks that was the answer I was looking for