Open felix-ht opened 5 months ago
One faster option, that is still better than the currently possible serialisation based approach, would be to go with the threads proposal for wasm.
This is in the specification phase 4, instead of 1 so might land within a reasonable time frame.
An incremental adoption would still be my preferred variant:
The upside would be that 1 and 2 should have easy webworker equivalent so the api could be kept consistent between JS and WASM
If serialisation is not an option we could also be to go with creating sperate workers on the js side and sharing data with SharedArrayBuffer or with tranferable objects. This is what Emscripten and wasm-bindgen-rayon This could also work seemlessly for dart2js.
One faster option, that is still better than the currently possible serialisation based approach, would be to go with the threads proposal for wasm.
Threads proposal only allows sharing linear memory - you can't share Wasm GC structs, that's why we need shared everything threads proposal.
So with what is available right now in Wasm (even with threads proposal) you can only send structured data by copying it, and only typed arrays backed by SABs can be really truly shared.
Thanks for sharing that info @mraleph i wasn’t aware of the Wasm GC limitations!
Currently,
dart2wasm
lacks support for isolates, dampening my enthusiasm for WASM as a means to achieve seamless concurrency on the web.Referencing this issue, it appears that an upstream dependency prevents the implementation of isolates with native-like features. It will takes years until this is fully specified and implemented in (all modern) browsers.
@mraleph's metioned the possibility to implement a simplified version of isolates, albeit with certain limitations. These limitations seem to include:
Despite these constraints, I would prefer this limited form of concurrency over none. The absence of effective concurrency options means tasks like parsing large files or responses lead to performance issues. The current solution using web workers is unwieldy and starkly conflicts with Dart's commitment to providing a great developer experience.