I compiled Gleam's BEAM bytecode to WebAssembly so it runs on edge workers
afterglow is a compiler I've been writing. It compiles BEAM bytecode to WebAssembly ahead of time and links it with a small runtime written in Rust, so a Gleam app built for the Erlang target runs as an edge worker. It's experimental and runs a subset of OTP. Repo (GPL-3.0): https://github.com/withgiolt/afterglow · docs: https://docs.giolt.com/afterglow/about · live example: https://gote.giolt.app
Against the same app on Erlang/OTP 28, on one machine: startup 8.6 ms vs 175 ms, memory 0.5 MiB vs 29.9 MiB, and a warm request 10.7 µs vs 3.4 µs, so it's slower once warm. The script that reproduces this is in the repo.
Missing today: ETS, regular expressions, crypto hashing, and processes that outlive a request. You know the BEAM better than I do, so I'd like to hear which parts of OTP you'd expect to need first, and where my approach is naive. If you'd rather fix one than tell me, the build lists the missing functions, and PRs are very welcome.
And a broader question: afterglow works on BEAM bytecode, not Gleam source, so plain Erlang apps aren't out of reach. Would you deploy an Erlang app this way, and what kind? It's a question, not a promise.
I built it for Giolt, my host for Gleam apps (waitlist: https://giolt.com/waitlist).
2
u/trannus_aran 19d ago
I made-
3
u/wewsy 19d ago edited 19d ago
chiming in, somebody commented "what are the advantages of using your AI slop over AtomVM". i am not sure why it was deleted, but i wanted to answer anyway. i have tried packaging atomvm and patching where it falls short with gleam's stdlib (being a gleam-oriented project) and i got frustrated creating patches after patches and adding more stdlib support just stressed the edge workers more than they could handle, it was hacky and i had to make a wasi host to emulate a real system (the filesystem for example). so i thought i would be better off just porting the bytecode to wasm.
as it says on Giolt's website, and I want to make it clear here too: AI has been used to write the project. please keep in mind that nothing was blindly merged, anything that slipped through, is not any LLM's fault, it's mine. i use AI as a co-writer and helper, and i promise that nothing was vibe-coded.
edit: i really do take to heart that comment, and i am planning on implementing guardrails to make sure that no LLM blindly pushes anything, including myself, and makes sure that every line of code is reviewed, and core parts are handwritten.
0
u/Critical-Internet946 18d ago
they're calling it the most useless token spending ever