5 ms·
Sad that Scala.js will not use WebAssembly, since WebAssembly doesn't provide GC.
by partycoder 9y ago
Sad that Scala.js will not use WebAssembly, since WebAssembly doesn't provide GC.
- sjrd 9y agoWebAssembly will most likely eventually provide a GC, at which point we'll do what we can to support compiling to wasm. See also: https://github.com/WebAssembly/gc/pull/1#discussion_r110997852 https://github.com/WebAssembly/gc/pull/1#discussion_r1109978...
- themihai 9y agoThey don't seem be on Chrome roadmap. We'll all grow full beards by the time DOM and GC become available. https://wasmdash.appspot.com https://wasmdash.appspot.com
- sjrd 9y agoGC support can hardly be on Chrome's roadmap when the design of the spec has hardly anything more than "we want to have it, and here are some vague goals". So yes, we'll grow beards, but it will happen. Remember though that wasm as whole happened in only a few years!
- user1241320 9y agoMy two cents: to me WebAssembly seems like something Scala Native might address, more than Scala.js. Or even better, both project can sort of blend for this purpose as on one hand (SN) addresses LLVM compilation and the other (SJS) is perfect JS interop (not so sure how WebAssembly does that).
- sjrd 9y ago> not so sure how WebAssembly does that Basically: badly. That's the number one reason we're not trying to compile Scala.js to wasm at the moment. For wasm to get the level of JS interop that Scala.js has, it needs to integrate with JS objects, which means with the JS GC, which means basically have a GC of its own. Hence we're waiting for the wasm GC spec to take life :)
- user1241320 9y agoI, sort of, know the limitations WebAssembly has right now when it comes to JS interop (such as only being able to use functions with numbers as parameters!) but my guess is this is temporary. It'd be curious to see experiments doing something Scala Native -> Emscripten -> JS-land. Regardless, thanks so much for the work you're doing with Scala.ks (Scala is still my main language and I'm working on removing JS from my toolbox soon). https://youtu.be/HktWin_LPf4?t=22m31s https://youtu.be/HktWin_LPf4?t=22m31s
- mafribe 9y agoScala.js could write their own GC to hook into WASM as a library, and ship it with Scala.js until WASM has its own GC. Indeed, such competition could spur on the the WASM team(s) to accelerate work on GC.
- sjrd 9y agoThat would not solve that essential part: > it needs to integrate with JS objects, which means with the JS GC Otherwise we would have done it already.
- mafribe 9y agoCould you not have a radical separation between data to be collected by Scala.js GC, and data GCed by Javascript? Data that crosses the boundary is deep-copied so as to avoid interference between both collectors? Not good for performance, but possible in principle, and a stop-gap measure until the WASM GC lands.
- sjrd 9y agoI'm not sure what you mean by "deep-copied" in this case. But I suspect it would involve losing the identity of the objects, which is unacceptable for correctness. Moreover, typical Scala.js code constructs cyclic dependencies between Scala objects and JS objects routinely. If Scala.js has its own GC, you'll have to manage those cyclic heap references, which will involve weak maps and other trickery so complicated that we would most likely lose all the performance that wasm would otherwise bring us. It's just not worth it.
- Matthias247 9y agoWhat do you exactly expect from targetting WASM instead of JS? Higher performance? Smaller bundles and faster load times? Better interoperability?
- sjrd 9y agoBetter interoperability, definitely not. Scala.js already has the best interoperability out there, excluding languages with the same run-time semantics as JS (such as TypeScript). In fact, it is the lack of good interoperability in wasm that currently prevents us from compiling Scala.js to that target. We could hope for smaller bundles and faster load times, yes. But mostly we should be able to get faster "cruising" execution. Scala.js being statically typed, there is a lot of static guarantees that we lose when compiling to JS. JS engines are very good and can "recover" a lot of it through JIT'ing, but it's still 3x slower than Scala/JVM on average (after warmup of both), so clearly we lose something non-negligible. By compiling to wasm, we would lose the JIT, but keep the static types. It is unclear how fast we would manage to be, but I would hope we can get within 2x of the JVM instead of 3x-ish. There is a lot of misconception on the Internet that "wasm makes everything faster". For example, a lot of people want to "compile JS down to wasm" to make it faster. That's bullshit, because your language does not have static types to begin with, so you lose the JIT and gain nothing in exchange, which means you'll run much slower. But if you compile a statically typed language down to wasm, you should be able to gain some significant speed.
- paulddraper 9y agoYeah, but Scala started out on a JIT runtime. I'm skeptical a non-JIT would really be that much better.
- sjrd 9y agoAs I said in the parent, in the case of Scala.js, I believe we lose more performance because of the loss of static types than we would if we lost the JIT. Performance measurements in Scala Native, which has no JIT and is still quite young (so not very optimized yet), suggest than we can easily be within 2x of the JVM for Scala code, even without JIT.