Hello, on the web (using wasmJsMain target), compr...
# compose-web
n
Hello, on the web (using wasmJsMain target), compressing an image renders Compose frozen, even if I use Dispatchers.Default. If I understood correctly (and feel free to correct if I'm mistaken 🙂), it's because web is basically single threaded. We can leverage "parallel execution" of the coroutines because they suspend ("yielding the thread" to another coroutine) instead of blocking it. That's good until I want to do heavy computation that is not coroutine friendly (hello skiko) and will basically "block/exhaust" the thread for several seconds while doing the computation. Is everything stated above correct ? If so, what are the possible alternatives to avoid freezing my Compose Web UI while doing heavy computation ? Thank you !
c
I.e check this PR for coils decoding Images in a web worker. https://kotlinlang.slack.com/archives/C01F2HV7868/p1770661079716249
n
Wow that's super complex, after 15min I still understand 1% 😞 I swore to myself to never read / write JS again, I guess I'll accept the multi seconds UI freeze when resizing images on Web 😞 Thanks a lot for the help ! 🙂
🤔 2
m
That's not so bad. In just about 24.75 hours you'll have it 🙂. Waiting for true multithreading in browsers will probably take longer.
😂 3
n
I shall become crazy after 24.75 hours of reading JS, I'm sure of that 😂 Every bit of information around this topic is either severly outdated, involves stuff I can't start to understand, or both. Between Kotlin/JS removing so much stuff in a couple of years, Kotlin/WASM relying on JS but at the same time not completely, configuring targets in Gradle changing shape 2 or 3 times already, and the inherent fuckery of JS, that task is way too hard for me. I will wait for a good example / article not involving JS, or I will just accept the bad UX anyway, can't be beggars with experimental stuff 🤷
c
You don't need JS to run a web worker. There are wrappers for it in Kotlin. 🤷🏻‍♂️ Check out https://kotlinlang.slack.com/archives/C0B8L3U69/p1772846600676889?thread_ts=1772836173.840919&channel=C0B8L3U69&message_ts=1772846600.676889
n
I've stumbled accross this repo but AFAIK it doesn't work in WASM (someone else said in another thread mentionning this repo). Source https://slack-chats.kotlinlang.org/t/28919894/does-anyone-have-an-example-of-using-web-workers-with-kotlin#837bf408-62f7-4356-b4dc-f016efb7a15b