nsuchy

nsuchy

With WebAssembly just getting started do you guys think that one day we’ll be able to run Elixir in the web browser and use it to do similar tasks that Javascript does today?

Showing Posts 18 to 9

blatyo

blatyo

Conduit Core Team

I don’t know that it’s impossible, but I feel like it wouldn’t be very performant. I don’t think the BEAM is optimized to perform the types of operations that are necessary to run WASM code.

blatyo

blatyo

Conduit Core Team

When I was at CodeBEAM SF, I learned there was a group of people (not sure who), who were looking at porting the BEAM to Rust, so they could take advantage of Rust’s ability to compile to WASM. However, it sounded like it was in very early stages and there were some complexities in how the BEAM made some dynamic calls (if I remember correctly). I wouldn’t be surprised if it’s a couple years before it sees the light of day if ever.

richardpringle

richardpringle

What about running wasm modules on the beam? I think that would be useful for portability of code. For instance, it would be great if I could get the fault-tolerance guarantees of the BEAM by running a containerized version of something in the beam itself (something like SQLite for example).

msand

msand

Thanks for the links! I was also thinking of the possibility of message passing between workers more like sending messages over the network, and running beam processes inside each worker. Fault tolerance and ability to update code in runtime are interesting for some use cases I have in mind at least. And I have at least one p2p experiment I’d like to try where high-availability would be useful as well.
Rust has relatively good bindings to almost all the apis exposed by browsers now: https://rustwasm.github.io/wasm-bindgen/api/web_sys/
While things like RTCQuicTransport are obviously missing, but that can be worked around anyway, as there’s the escape hatch of calling into js and having access to all the apis from there.
At least for the kinds of experiments I’m thinking of, the size of the assets for the vm wouldn’t matter too much, as those would be updated relatively rarely and could be cached quite well.

peerreynders

peerreynders

Being thread-based, Web Workers are heavyweight (compared to BEAM processes) and data transfer between them isn’t particularly fast (thread hop delay 1- 15ms) - which likely explains the focus on SharedArrayBuffer.

Edit: It seems threads for WebAssembly start web workers without the overhead of 4MB for each V8 isolate for JS and share wasm modules.

Google seems to be working on developing a web standard scheduler/task processor for browsers.

See further:

So I suspect that adapting the BEAM scheduler for the browser environment is a non-trivial port and one has to wonder whether the resulting size of the WebAssembly asset may constrain its usefulness.

You need to implement a fault-tolerant, scalable, soft real-time system with requirements for high availability.

… and while concurrency is an obvious goal on the browser, I don’t think anybody is giving fault tolerant or high availability much thought or value.


For the time being WebAssembly for the browser seems to have a role that is similar to NIFs for the BEAM. So it makes sense that C, C++, and Rust are the officially supported languages, while everything else is considered (highly) experimental.

Making the browser do things, scripting the browser via the various browser APIs, is still the domain of ECMAScript.

Web Assembly Concepts:

  1. By itself, WebAssembly cannot currently directly access the DOM; it can only call JavaScript, passing in integer and floating point primitive data types. Thus, to access any Web API, WebAssembly needs to call out to JavaScript, which then makes the Web API call. Emscripten therefore creates the HTML and JavaScript glue code needed to achieve this.

(There are future plans to allow WebAssembly to call Web APIs directly).

msand

msand

I haven’t tested it yet, but looks very interesting. I was looking into running multi-core logic in the browser recently, and have the emscripten pthreads examples working fine, but it requires allowing shared-array-buffer, which kind of opens up spectre / all the speculation bugs, perhaps a bit more than necessary (and it’s only available behind flags atm).

I was thinking perhaps someone would’ve used BEAM with message passing between Web Workers rather than shared memory, to get scalability without opening up bugs in the hardware architecture. But seems this hasn’t really caught on properly yet.

There was discussion about a rust rewrite in 2017 Redirecting to Google Groups
i’m happy someone is working on it at least :slight_smile:

wanton7

wanton7

There is Enigma VM as well. It might support WebAssembly in the future GitHub - archseer/enigma: An Erlang VM implementation in Rust · GitHub

kelvinst

kelvinst

That’s really cool! Have you tested it?

msand

msand

There’s at least:
https://github.com/jamen/elixir-wasm

And elixirscript can run Elixir in JavaScript, and might run in Wasm later on
https://github.com/elixirscript/elixirscript
https://github.com/elixirscript/elixirscript/issues/454

Seems AtomVM can run erlang in Wasm
https://github.com/bettio/AtomVM/issues/30

LTheGreats

LTheGreats

Is there any news on weather or not Dockyard is still working in compiling the BEAM to WASM?
(or other organizations or people working on a similar project)

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews