6 ms·
It seems like it uses Web Workers (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers https://developer.mozilla.org/en-US/docs/W
by twiss 6y ago
It seems like it uses Web Workers (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...)
- brundolf 6y agoTo get more specific for those who may not be as familiar with the nuances of JS: JS can start parallel threads, it just - importantly - cannot share memory between them (instead it must pass messages, copying data at boundaries). This eliminates a large number of benefits and usecases that tend to be associated with "multithreaded programming", but saying JS "isn't multi-threaded" isn't quite true.
- twiss 6y agoFor what it's worth, there's some limited ability to share memory (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...), though you can only share binary data, not other types, and it only works in secure and cross-origin isolated contexts, due to security concerns. That being said, at first glance it doesn't look like Clio is using this, instead it's passing messages as you suggest. It might actually be interesting to use SharedArrayBuffers as a compilation target, as they're probably hard to use correctly manually. That being said, WebAssembly threads (https://github.com/WebAssembly/threads https://github.com/WebAssembly/threads) may be more appropriate for this. For completeness, Workers can also transfer memory (https://developer.mozilla.org/en-US/docs/Web/API/Transferable https://developer.mozilla.org/en-US/docs/Web/API/Transferabl...) with less security restrictions. They can also collaborate by accessing a shared database (https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_A...) though this is obviously slower than shared memory.
- deleted 6y ago[deleted]