Doesn't kotlinx.coroutines support true multi-thre...
# compose-web
k
Doesn't kotlinx.coroutines support true multi-threading on WASM target ? I know it's experimental but it's an interesting WIP It seems wasm introduced atomic operations to lay the groundwork for true multhreading but it's apparently not rolled out or stable on all browsers ? or is it already there with all android-like dispatchers and true multithreading support instead of some scheduling magic on a single thread at the end of the day.
Copy code
While Dispatchers.Default and Dispatchers.IO are supported in Kotlin's coroutine model, their behavior on WASM is constrained by the current state of WebAssembly's threading support. These dispatchers typically rely on background threads or thread pools to offload tasks, but in WASM, where true multithreading is still experimental and not universally supported, these dispatchers will operate in a similar way to Dispatchers.Main, running tasks on the same main thread.
It almost sounds like what we're seeing here is a sophisticated scheduling optimization found precisely in Javascript target, which is constrained obviously by javascript's 1 main thread restriction. Right ? edit: found on rust forums that WASM Threads are released for chrome already with atomic ops and
SharedArrayBuffer
! but not for other browsers 🤔
a
As far as I know, only the atomics are supported: https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md https://caniuse.com/wasm-threads And the threads still should be implemented by WebWorker So, you can't spawn a specific Wasm function in a separate thread What makes a bit hard implementing coroutines on top of this API
👀 1
💯 1
p
when using certain functions in kotlin wasm (serializing images to base64), it blocks the whole ui (using launch dispatchers default). The bigger the serialized object the more problems it creates. i dont know if its my implementation or its only because its singlethreaded
a
@Pau Marzo may I ask you to share it in the #C7A1U5PTM channel too?
👍 1
p
No response there🥲
a
@sandwwraith ^^
194 Views