This article explains how Scala.js supports Wasm. You will learn the current status of Wasm support in Scala.js and the reasons why chose Scala.js over ScalaNative.
thanks for the detailed explanation. i've been wanting to try wasm using scala for a long time and you guys just made it possible. what an heroic effort!!
i have a couple of questions though:
1. the js generated after fullLinkJS is actually smaller than wasm by quite a big margin. shouldn't wasm code be smaller than js?
1. The JavaScript with Google Closure Compiler, which is optimizer for JS, is currently smaller than the Wasm. On the other hand, we haven't applied an optimizer like wasm-opt to Wasm yet, due to the lack of support for a specific feature (https://github.com/WebAssembly/binaryen/issues/6407, which should be supported soon!)
Once supported, `wasm-opt` would reduce the binary size even further.
Additionally, while the Scala.js JS backend has benefited from 10 years of optimization, our Wasm backend is still in its very early stages and just did only a few optimizations. I believe there is significant potential for further optimization, and making binary smaller than JS with GCC :)
2. The experimental version of this feature would be available with the next Scala.js release, but I can't tell when it would be :/
thanks for the detailed explanation. i've been wanting to try wasm using scala for a long time and you guys just made it possible. what an heroic effort!!
i have a couple of questions though:
1. the js generated after fullLinkJS is actually smaller than wasm by quite a big margin. shouldn't wasm code be smaller than js?
2. when can i try it?
Hi, thanks Walter :)
1. The JavaScript with Google Closure Compiler, which is optimizer for JS, is currently smaller than the Wasm. On the other hand, we haven't applied an optimizer like wasm-opt to Wasm yet, due to the lack of support for a specific feature (https://github.com/WebAssembly/binaryen/issues/6407, which should be supported soon!)
Once supported, `wasm-opt` would reduce the binary size even further.
Additionally, while the Scala.js JS backend has benefited from 10 years of optimization, our Wasm backend is still in its very early stages and just did only a few optimizations. I believe there is significant potential for further optimization, and making binary smaller than JS with GCC :)
2. The experimental version of this feature would be available with the next Scala.js release, but I can't tell when it would be :/
Thanks for the prompt reply! looking forward to play with it soon
Out of curiosity: How does Scala Native handle garbage collection? And why wasn’t it an option to do it the same way for scala.js compiled to WASM?
In ScalaNative, we implement our own garbage collector (GC) or rely on libgc. You can see the implementation here https://github.com/scala-native/scala-native/tree/75047a4d9b74cdd27233317730e5de0629690bb2/nativelib/src/main/resources/scala-native/gc
We could port these GC algorithms to Wasm and embed our GC implementation into the Wasm module using Scala.js (or ScalaNative), instead of relying on WasmGC. However, this approach would encounter the issues discussed in https://dev.virtuslab.com/i/146705467/embedding-a-custom-garbage-collector