Hacker News new | ask | show | jobs
by sjrd 3308 days 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 :)

2 comments

I, 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

Scala.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.
That 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.

Could 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.

I'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.