threads.js icon indicating copy to clipboard operation
threads.js copied to clipboard

isolated-vm

Open tcf909 opened this issue 4 years ago • 6 comments

Has there been any consideration regarding supporting https://github.com/laverdet/isolated-vm as an alternative to nodejs workers?

There are some inherent benefits like cpu / mem limits, inspector debugging, etc...

tcf909 avatar Jan 23 '21 02:01 tcf909

Hey @tcf909. No, it has not been considered before. Thanks for pointing out!

I am curious, though: Under "Alternatives" its readme states that

though if parallelism is your only goal then there are probably better options out there [then isolated-vm]

I wonder what the trade-off is, since we are primarily concerned about parallelism. Not sure if it provides the same runtime performance, for instance. I guess that it also doesn't come with an IPC solution out-of-the-box.

andywer avatar Jan 23 '21 15:01 andywer

In what little experience I have with it the performance is on par (if not better) than the native solution.

I don't think native IPC would be that tough. Just data being transferred which it has plenty of primitives for.

In my experience with one of the other packages the author wrote (Fibers) he is a top notch developer (way ahead of most of the core contributors for Node -- my benchmark) and my guess is being at that level leads him to be overly specific as to not perpetuate any misinformation.

I would say the downside of having to compile the module is a so-so trade-off for having the added features.

https://github.com/laverdet/isolated-vm

@laverdet any thoughts?

tcf909 avatar Jan 28 '21 23:01 tcf909

Thanks for the kind words. The primary selling point of isolated-vm is being able to run untrusted code in a clean JS environment. If you don't need that then I'd definitely just recommend using worker_threads.

laverdet avatar Feb 02 '21 08:02 laverdet

@laverdet any thoughts on a comparable interface to Node.js MessagePort?

tcf909 avatar Feb 02 '21 20:02 tcf909

You would use a Reference to a function in the other isolate. The examples section in the readme has a basic example of implementing console.log. It's just functions calling other functions, and then you can implement more sophisticated abstractions on top of that.

laverdet avatar Feb 02 '21 22:02 laverdet

Thanks, @laverdet!

@tcf909 I wonder if a Worker implementation using isolated-vm under the hood might be a good thing to implement as an external community package. We would just need to figure out how to use it in a way that the webpack plugin will be able to recognize those workers, too.

andywer avatar Feb 03 '21 09:02 andywer