Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of running GenServers in the browser #1161

Open
venkatd opened this issue May 19, 2024 · 2 comments
Open

Possibility of running GenServers in the browser #1161

venkatd opened this issue May 19, 2024 · 2 comments

Comments

@venkatd
Copy link

venkatd commented May 19, 2024

Hi, I saw the lightning talk and that led me here.

I was curious what the feasibility of running Elixir GenServers in the browser is using webassembly.

What is the performance like? How large is the VM payload? Is this compatible with OTP meaning it could interoperate with the BEAM?

@pguyot
Copy link
Collaborator

pguyot commented May 20, 2024

Hello, thank you for your interest in AtomVM emscripten port.

OTP gen_server can run in the browser using webassembly as demonstrated by the following demo code:
https://github.com/atomvm/atomvm_examples/tree/master/demos/supervised_discs

I guess the same code could be rewritten using Elixir.

Performance is good enough for this example, using several threads (and cores) on the browser. The main slowness in this case is related to DOM manipulation and a better implementation should use HTML5 Canvas for rendering :-)

Interoperation is a different story. Code running in the browser has limited network capabilities (cannot do arbitrary TCP) and AtomVM currently doesn't support disterl. So an Erlang node running in the browser is unlikely. Still, we could use Emscripten fetch API and maybe have the code in the browser interact with an Erlang or Elixir web server. Bindings for FetchAPI are not available but would be very easy to add.

What use case do you have in mind?

@venkatd
Copy link
Author

venkatd commented May 20, 2024

Thanks!

At this point it is just a curiosity. I thought it would be an interesting use case to be able to write Elixir full stack with normal message passing between processes over the network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants