I’m grateful for the vision of Elm - it doesn’t need to compromise - it’s a small growing tree - it’s a baby tree that we can see is going to be massive and strong just from how well and healthy its’s roots are.
That doesn’t make it a grown tree and hanging all sorts of ornamental garbage off it isn’t going to help it grow tall and strong.
And will continue to be the runtime of Elm at least 3-5 years into the future.
Guesstimation based on the fact that there is no GC in webasm yet. Once that’s done, it will still take some time until all major browsers will implement it and then it will probably be shipped behind a flag for a time. I doubt that an official webasm port will start before at least there is some official GC support in webasm to allow for easy experimentation.
Of course, unofficially, someone could implement an Elm compiler that would output C or Rust and compile that to webasm but the results would probably not be optimal. The runtime alone might be in the hundreds of kb. However, I might be wrong…
The good news is that Elm might be one of the languages that could be used to optimize the GC for target code from functional programming languages.
I’m not aware of WASM’s spec or roadmap though i have worked with ASM.js - I would expect that the actual details of memory management would be part of the browser layer - and routines in WASM would integrate with that existing or future memory management system ( this is what something like “new” does now - integrate with the nuances of the browser’s allocation runtime)
AFAIK the problem is that right now you would need to implement your own garbage collector on top of the single chunk of memory that is assigned to your app while a perfectly battletested one lives just around the corner in the browser. You could do it but there’s really not much sense in doing so, you’ll never match the man-hours put into say Chrome’s garbage collector. Rust can run right now because they have memory management inside the language via their borrowing system.
From what I’ve gathered the roadmap is indeed very vague but it was mentioned that they want to bring DOM handling APIs into WASM, which right now you can only do Elm style via “ports” to the outside context. Some time after that supporting the browser garbage collector is scheduled… but that has also been the case for ASM.js sooooo, we’ll see whether that ever happens and if it does when this is due.
A very good and recent talk can be found on the GOTO Conference YouTube. I’d regard that as the number one source on WASM right now.
Regarding the GC: I recall that Evan wrote on one of the mailing lists that removing the possibility of cyclic pointer structures in Elm is something he’s considering. That would enable plain old reference counting a valid memory management strategy. That would simplify things. Still, a WASM target would be a major piece of work.
If you use the LLVM compiler framework to generate your WASM code - it already includes a lot of support for garbage collection. It does not provide a complete ready made GC, because the exact implementation always depends on the language, but it does provide a lot of tools to build one. So writing the garbage collector may not be such a blocker as people think.
Also, GC version 0.01 - just start simple with a pause-the-world mark-and-sweep collector. Good enough to get started, then refine from there.
This seems to be the current mind-set. If we stay that way, WASM is just something we talk about and never do.
There are a couple of folks experimenting with compiling Elm or similar/sub-sets to WASM that I hear about now and again on Slack. To me this is much more encouraging; just get stuck in and have a go, there is a lot to learn and figure out.
I wrote a Prolog compiler once - it had no GC so was just a toy; after running for a while it would run out of heap space and crash. I was hung up on the GC because it seemed difficult. Eventually I wrote a simple mark and sweep collector in about a day (you can find the algorithm in a text book), and then wondered why it took me so long to do that. Of course, my pause-the-world collector isn’t the best that could be done, but it was a major step forward for a small investment of effort.
@ElmModerationTeam Hi… Is it possible to fork this conversation about garbage collection - it seems like people are really interested in talking about it.
For example : I want to have a client service to a remote backend service do non-critical to user flow work - but and i need to guarantee that my “client service” is not going to crash or impact the user experience.
An Elm worker with a port filled this niche nicely.
@rupert@ram9cc that’s true ASM is more of a Mozilla pet project but the same people who worked on that at Mozilla seem to be in the same boat with the former NaCl staff of Google so there is indeed hope. LLVM might be an option but you’d still need to write a backend for that.