5 Comments
Jul 29Liked by Rikito Taniguchi

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?

Expand full comment
author
Jul 30·edited Jul 30Author

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 :/

Expand full comment
Jul 30Liked by Rikito Taniguchi

Thanks for the prompt reply! looking forward to play with it soon

Expand full comment
Jul 25Liked by Rikito Taniguchi

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?

Expand full comment
author

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

Expand full comment