# Elm core libs in WebAssembly

**URL:** <https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443>\
**Category:** Show and Tell\
**Created:** [October 7, 2019, 7:30pm UTC](https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443 "2019-10-07T19:30:31Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Brian\_Carroll](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/brian_carroll/32/444_2.png) [@Brian\_Carroll](https://discourse.elm-lang.org/u/Brian_Carroll)\
**Post date:** [October 11, 2019, 5:45pm UTC](https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443/24 "2019-10-11T17:45:22Z")

</div>

> [@jreusch](#):
>
> Oh, I was not aware of that! I had assumed that I worked like Windows or Linux, where you can just `VirtualAlloc` or `mmap` if you ran out of memory or needed another arena

Oh yeah, you can definitely request more memory! But you don’t see two `ArrayBuffer`s in JavaScript. You see one `ArrayBuffer` that grows. Or viewed from the C/Wasm side, one [linear memory](https://webassembly.github.io/spec/core/intro/overview.html#memory) that grows. I’m sure the runtime is hiding all sorts of magic though.

> [@jreusch](#):
>
> so the _compact_ phase of the GC should just copy them anyways into the old generation if they survive `update` . This would require to always run the GC before calling `view` though.

Yep. That’s part of the complexity I was talking about! It’s all achievable, it’s just more complex. There are two regions being managed in completely different ways and there are side-interactions between them. So every time you do something in one region you have to mess about with the other region too. I have a sense that more edge cases will emerge, because it’s complex in the [Rich Hickey sense](https://www.youtube.com/watch?v=rI8tNMsozo0) of things being intertwined. _And that’s kind of normal for GCs!_ It’s still way simpler than V8’s [Orinico](https://v8.dev/blog/trash-talk), for example! It could be a good direction for the future!

---

<div class="post-metadata">

**Author:** ![MartinKavik](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/martinkavik/32/2584_2.png) [@MartinKavik](https://discourse.elm-lang.org/u/MartinKavik)\
**Post date:** [October 13, 2019, 8:49am UTC](https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443/25 "2019-10-13T08:49:16Z")

</div>

Hi. It’s very interesting topic.  
I just want to add some Rust libs for inspiration, because I’m writing a Rust framework and I’ve rewritten Richard’s RealWorld example to it a few months ago, so I think that Rust-WASM world is mature enough.

- [dodrio](https://github.com/fitzgen/dodrio) - One of VirtualDOMs for WASM.
- [Shifgrethor](https://boats.gitlab.io/blog/post/shifgrethor-i/) - GC in Rust (there are also links to other GCs).
- [gluon](https://github.com/gluon-lang/gluon) - Garbage-collected functional language compiled to Rust.
- [Elm parser](https://github.com/michaeljones/elm-parser) - Elm parser written with [Nom](https://github.com/Geal/nom).
- [Pest](https://pest.rs/) - Another parser.
- [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) - It generates “plumbing” between Javascript/Typescript and Rust/WASM. And it contains wrapper for WebAPI.

_Note:_ I saw `TextDecoder` somewhere in comments above - I have to add [polyfill](https://github.com/MartinKavik/seed-quickstart-webpack/blob/master/entries/templates/head_scripts.hbs) to my Rust apps to make them work in all browsers.

---

<div class="post-metadata">

**Author:** ![Brian\_Carroll](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/brian_carroll/32/444_2.png) [@Brian\_Carroll](https://discourse.elm-lang.org/u/Brian_Carroll)\
**Post date:** [October 16, 2019, 6:44pm UTC](https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443/26 "2019-10-16T18:44:09Z")

</div>

Thanks for sharing!  
As I mentioned in the README of my repo, I don’t think my Rust skills are advanced enough for this, but if someone who knows it better wants to do a project like this I will gladly give them some pointers… [#dadjokes](https://twitter.com/search?q=%23dadjokes)

---

<div class="post-metadata">

**Author:** ![Brian\_Carroll](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/brian_carroll/32/444_2.png) [@Brian\_Carroll](https://discourse.elm-lang.org/u/Brian_Carroll)\
**Post date:** [October 16, 2019, 7:06pm UTC](https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443/27 "2019-10-16T19:06:57Z")

</div>

Hey everyone, thanks so much for all the comments, this has been a fantastic thread!

I’ll do some more posts whenever I have news to report. Here’s roughly the next steps as I see them right now. This could obviously all change.

- Create a wrapper or interface between a WebAssembly module and Elm kernel JavaScript.

- Finish code generation for the full Elm AST (outputting both C and JS). Compile some proper programs and play around with them.

- Do some analysis on memory profile or real programs, what runs fast or slow, etc.

- Try migrating VirtualDom diffing to Wasm, with JS just applying patches.

- Look into further GC optimisations for VirtualDom as suggested above

My general approach is to explore all the different pieces, then work on the biggest unknown until I understand the important issues and/or solved some problem. Once I feel like I understand that well, move on to the next biggest unknown.

This means gradual progress on lots of pieces in parallel, with no end-to-end system for quite a long time. I’ve been told this approach seems weird to some people, but it’s how I do it. I feel it will lead to good design choices.

I’d like to have good [docs](https://github.com/brian-carroll/elm_c_wasm/tree/master/docs) on this so I’d welcome GitHub issues on that particularly.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [October 26, 2019, 7:07pm UTC](https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443/28 "2019-10-26T19:07:01Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.elm-lang.org/t/elm-core-libs-in-webassembly/4443.md?page=1)
