Popcorn - a new tool to run Elixir in browsers

Popcorn lets you run Elixir code in the browser via WebAssembly. It builds on top of AtomVM, a tiny Erlang VM. It’s early stages and breaks sometimes, but you can run Elixir code and even Elixir and Erlang compilers right from the browser.

We created some cool examples too - check them out at popcorn.swmansion.com, and the repo is available at

Happy hacking :wink:

46 Likes

Nice, are there any performances improvements vs running regular?

Could be interesting to see how GitHub - elixir-dbvisor/sql: Brings an extensible SQL parser and sigil to Elixir, confidently write SQL with automatic parameterized queries. would do vs running it on the backend.

What do you mean by ‘regular’? It’s definitely slower than the BEAM

Great, how much slower, would the reduce latency make up for the loss of performance.

When I talk about regular, then I mean standard release. We tend to run the VM on servers, this as I understand would allow us to run our code on the client, in this case the browser.

How so? Isn’t the whole point to have better performance but not all BEAM features?

Awesome. Glad to see the dream of Elixir-in-the-browser is being kept alive!

2 Likes

This is really cool! I just cross-posted on EFS in the AtomVM forum :icon_biggrin:

3 Likes

Great, how much slower

We don’t have proper benchmarks yet. For now, we focus on stability.

would the reduce latency make up for the loss of performance

That’s, of course, dependent on the use case and expected latency, so you’d need to benchmark your particular scenario :wink:

this as I understand would allow us to run our code on the client

That’s correct, I wanted to make sure I got it right

1 Like

No, it’s quite the opposite :smiley: The goal is to run Elixir code on the client side. It would enable features like IEx or HexDocs examples running in the browser, but also local-first applications in Elixir. We aim to provide as many BEAM features as we can, if they make sense in that context, and good enough performance for these use cases.

10 Likes

Hi. I asked about this at ElixirConf, but my question wasn’t clear. :slight_smile: I’m referring to something like this: GitHub - cocoa-xu/nif_call: Call Erlang/Elixir functions from NIF.. Could Atom be embedded as a library to have an Elixir runtime inside C, like the embedded Python interpreter? If so, would calling simple Elixir code be faster? Right now, using a NIF with an Elixir callback is complex. Maybe embedding AtomVM in a NIF would offer better performance.

Okay, I got it now, thanks for clarifying :slight_smile: I think it should be possible to embed AtomVM as a NIF, but I’m not sure if it’s worth the effort. You would either need to effectively start the AtomVM just to execute a particular function, or have one running and communicate with it. Maybe the second way would be a bit faster than sending a message to the BEAM, but way more complex. Another problem is that the function wouldn’t have access to anything you already have running on the BEAM, and execution on AtomVM would be itself slower than on the BEAM.

But I can see the potential to use AtomVM for small, frequently executed scripts, as it seems to start faster than the BEAM.

This is awesome, thanks for building this! (And leveraging AtomVM is such a great idea.)

Out of curiosity, have you tried running the WASM build with Wasmex? Popcorn seems like it could be another great option for user scripting (@acco’s treatment of options for user scripting is wonderful: Microsecond transforms: Building a fast sandbox for user code).

I know Popcorn’s focus is on running in the browser, but curious if you think non-browser WASM applications could (potentially) make sense for Popcorn.

1 Like

This is in our backlog, but I’m unsure how hard it is. We’d need to make AtomVM compatible with WASI, which is the way to run WebAssembly on the server. The challenge is basically that WASI is quite limited in terms of which POSIX features you can use.

But I’d love to see that happen, too! From what I read, it would unlock some cool projects like Wordpress in Elixir :wink:

1 Like