WebAssembly progress update

I’ve been working on an unofficial port of Elm to WebAssembly for a couple of years now. When I posted last year I had just managed to get my first compiled demo app working.

Well, as we all know, it’s a long way from a first demo of a system to actually getting things running smoothly! So that’s what I’ve been working on. It involved rewriting parts of the core libraries and garbage collector, and lots and lots of tests!

I have a few demos and a blog post to share.

The main one is the Elm SPA example running in WebAssembly. There’s also the same thing in JS for comparison. Quick performance measurements in Lighthouse give pretty similar results between the two at the moment, which is a great start! There are improvements coming.

And if anyone’s curious about what’s been tested, there’s also the Elm core library tests in WebAssembly and the C runtime tests, both of which run in the browser.

This definitely isn’t for production. The build system only works for demo apps inside my repo, and it can’t handle multiple library versions.

More details in this blog post:

45 Likes

It brings me joy to see progress is being made on wasm support for Elm. Keep up the good work!

One thing I didn’t see mentioned in the article, what is the compile time like? Does compiling to C and then wasm add significant overhead?

Also could this project serve as a stepping stone for running Elm on platforms outside the web? Or maybe the decisions made to get it interop with JS also make it difficult to use elsewhere?

3 Likes

Oh yes, that’s true, I forgot to mention compile times!
I ran a build of elm-spa-example just now, with an empty elm-stuff/. Elm to C took 1.7 seconds.
C to Wasm+JS took 5 seconds with full optimisations, or 3 seconds with no optimisations.

Yes it could serve as a stepping stone to other platforms, that’s one of the advantages of targeting C.

There would be a lot of other work involved of course. If you want Elm for command line apps or Elm for servers then you’d need to have good ideas for how to make those things nice, and then write libraries to implement that, and a lot of it would be in a low-level language like C.

But the JS stuff I’ve done wouldn’t get in the way much… I think! You’d probably need to add some kind of configuration options to turn things on or off, but that’s about it.

EDIT updated the compile times as I forgot I had another massive job running the first time!

7 Likes

This is truly awesome! Thank you for spearheading this!

2 Likes

Very interesting work!
One weird thing I have seen on the WebAssembly execution: in general, it turns out to be slower than javascript. Have you done any kind of targeted benchmarking to get an idea of runtime performance vs “traditional” js in some specific domains?
Eg: WebAssembly Zone - Daniel Lauzon - YouTube
Also I used your code as the basis for experimenting using Elm with multiple backend languages (eg rust, go), so: thank you!!

2 Likes

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