Nino
06/04/2026, 9:41 AMInt8Array(arrayBuffer) as ByteArray, while in Kotlin/WASM, it crashes: kotlin.ClassCastException: Cannot cast instance of Int8Array to kotlin.ByteArray: incompatible types. Any idea how? Code in thread.Nino
06/04/2026, 9:45 AMsuspend fun ByteArray.resizeAndCompress(
width: Int,
height: Int,
): ByteArray {
val arrayBuffer = decodeResizeCompressImageBytes(this, width, height)
return Int8Array(arrayBuffer) as ByteArray
}
private suspend fun decodeResizeCompressImageBytes(
bytes: ByteArray,
width: Int,
height: Int,
): ArrayBuffer
I'm trying to do the same as Coil did (offload image transformation to a Web Worker to avoid UI freeze during heavy computation), but I clearly have no JS / WASM skills and the documentation about this topic is lacking and / or obnoxious for someone without prior JS knowledge.Artem Kobzar
06/04/2026, 9:50 AMsuspend fun ByteArray.resizeAndCompress(
width: Int,
height: Int,
): ByteArray {
val arrayBuffer = decodeResizeCompressImageBytes(this, width, height)
return Int8Array(arrayBuffer).toByteArray() // On the JS - just cast, on Wasm - copy
}Nino
06/04/2026, 10:16 AMInt8Array with Int8Array(arrayBuffer) (or is it a simple wrapper?)
6/ And we're re-recopying in Kotlin/WASM with .toByteArray()
So if I understand correctly, we're copying once on the way to the Web Worker, and twice from the Web Worker (on WASM, only once on JS). That's 4x memory footprint, right?
Am I correct? This is a very difficult topic and I try to understand it better because it seems I will have to use it a lot, I want my Compose Web app to be performant and today the only way to offload work on Compose Web is through Web Worker only it seems.