Earlier quoted context omitted.
Sorry, but we need shared memory for fast sharing of large immutable data structures.
Then add immutable objects to JS, which enable a host of other optimizations and are useful in single-threaded contexts too. Shared-memory multithreading is just very difficult to use correctly. Actor-style concurrency hasn't really caught on (possibly because of the poor performance of workers and postMessage), but there is probably a middle ground that's easier for developers to get right.
Concurrent JavaScript: It can work
11–20 of 189 posts
Re: Concurrent JavaScript: It can work
#12Earlier quoted context omitted.
Sorry, but we need shared memory for fast sharing of large immutable data structures.
Shared memory could be hidden from the users. Passing objects would really be passing control of objects. If process A creates object a, and passes it to process B, no copying has to happen if the underlying mechanism uses shared memory and access control to effect the transfer (a change of owner).
Re: Concurrent JavaScript: It can work
#13Earlier quoted context omitted.
Then add immutable objects to JS, which enable a host of other optimizations and are useful in single-threaded contexts too. Shared-memory multithreading is just very difficult to use correctly. Actor-style concurrency hasn't really caught on (possibly because of the poor performance of workers and postMessage), but there is probably a middle ground that's easier for developers to get right.
JS already supports immutable objects, by using Object.freeze().
Re: Concurrent JavaScript: It can work
#14It's awesome to see work on concurrency, but I'd really like to se a model that didn't involve shared memory. JavaScript on the web already has the concept of Transferrables. It'd be great to explore how user-land code could create transferrable objects and graphs of them so they could be sent between threads without threads sharing the same heap.
Re: Concurrent JavaScript: It can work
#15Re: Concurrent JavaScript: It can work
#16Forgive the ignorance, but why do we need threads when we already have the event loop? And, as a follow-up, why introduce a new concurrency model that's based on Java instead of, say, creating a concurrent "event pool" where execution order isn't guaranteed and callbacks are executed with maximum concurrency (edit: to clarify, I mean maximum parallelism)?
Event loops are great for handling work that can be handed off occasionally to worker threads (like how Node works with libuv), but are awful when doing consistent CPU-bound work, such as with games, 2D/3D visualizations, finance, and the like. SharedArrayBuffer is a nice primitive that allows multiple Threads (or WebWorkers) to work on data in parallel. The additional primitives they're proposing offer quite a bit o…
Re: Concurrent JavaScript: It can work
#17It's awesome to see work on concurrency, but I'd really like to se a model that didn't involve shared memory. JavaScript on the web already has the concept of Transferrables. It'd be great to explore how user-land code could create transferrable objects and graphs of them so they could be sent between threads without threads sharing the same heap.
Also, most kinds of concurrency models will probably require the underlying VM to support some kind of shared memory. That's what this post is about.
Re: Concurrent JavaScript: It can work
#18Of course the language can be made to support it. Given the way Javascript is used, the question is whether supporting it will create a big mess. They have some good ideas. One is that variables can be marked as restricted to one thread. That should be the default. Other languages could benefit from that feature. Python, for example. If you want to get rid of the Global Interpreter Lock, knowing which variables can't…
Re: Concurrent JavaScript: It can work
#19Earlier quoted context omitted.
JS already supports immutable objects, by using Object.freeze().
That's not deeply immutable like you'd want for sharing objects across threads, or even for using in contexts like React and Redux.
Re: Concurrent JavaScript: It can work
#20Of course the language can be made to support it. Given the way Javascript is used, the question is whether supporting it will create a big mess. They have some good ideas. One is that variables can be marked as restricted to one thread. That should be the default. Other languages could benefit from that feature. Python, for example. If you want to get rid of the Global Interpreter Lock, knowing which variables can't…
In my opinion, concurrency isn't necessary for JS. If web developers want high-performance, concurrent computing, they should push for adding concurrency to WASM.
I doubt concurrency could hurt JS, but I just don't see any reason for it that concurrent WASM doesn't fulfill.