The BEAM is very lightweight and necessary within Erlang to enforce one of its greatest tradeoffs:
- No universal garbage collector, every process (aka green thread) has its own heap that is reclaimed when it dies.
- No process can takeover the CPU. If you run a hugely intensive task in one process, everything else, millions of other processes potentially, will continue responding normally and consistently. The hugely intensive task will just take longer.
There’s more that applies to some advanced use cases, but these are the 2 core elements that are awesome.
Glad you say you're coming around on the BEAM. It really is a fantastic virtual machine. Of course if you look at my comment history you'll see I'm a big fan of it and tend to push it, but that's only because it has actually made my job (and hobby) of engineering easier.
There's something elegant about how everything lives inside a process, and communication between those processes is crazy simple, you just `send(pid, value)` and boom you can not only talk across large codebases, but you can talk across _networked clusters of BEAM VMs_ with little setup.
At my current job, we're using it on embedded Linux for IoT devices, and it's really amazing to section off the code into processes that, if something like an i2c sensor or component glitches out, just let the process crash, and have it be restarted automatically by a Supervisor into a fresh well known state.
Definitely give it a look, it's nothing like the JVM ;)
The BEAM is an amazing piece of technology. It’s built to scale massive concurrent systems and has great developer ergonomics. I’ve used it with Elixir and it’s really a breath of fresh air as far as running a webserver goes. Much more flexible and simpler to manage than a python or nodejs runtime, and also capable of scaling up with far fewer resources than you would think. Highly recommend giving it a go!
I have never seriously used a BEAM language (Elixir/Erlang/Gleam), but for me, it’s the opposite: the most attractive part of Gleam is that it runs on BEAM :)
My reservations at this point are mostly around maturity of the language, the stdlib, and the library ecosystem; although I haven’t been following progress too closely.
As others have pointed out. The BEAM is one of the most efficient VMs out there. It isnt FASTER than C or C++ but it is insanely efficient. Stuff like a simple hello world fits in small bytes in memory. The resilience of the BEAM is impeccable. Discord reaps the benefits and uses Rust when it needs to. I love backend systems and my ideal backend always winds up being similar to what BEAM provides OOTB.
My only reason for not using it is nobody pays me to use it, they pay me to write basic CRUD apps in .NET
BEAM's concurrency model makes it the ideal runtime for web servers IMO. Similarly, the ubiquity of JS in the browser makes it an excellent runtime to target as well.
I agree though that it would be amazing to compile Gleam code into universal native binaries. Would make it a fatalistic general-purpose language.
AFAIK it's entirely possible -- just more of a resourcing concern given the small team.
I thought the whole point of Gleam is having a statically typed lang running in the BEAM VM? If you want something similar outside of it you probably want Scala, Rust, OCaml, etc.
I've found the JVM really gets in your way whenever you want to do something interesting with Scala. Rust is fantastic, but a lot of what I want to do can afford the overhead of a GC so that I can avoid lifetimes, borrows, etc...
I've not written any OCaml, but I've heard tell of its reputation of being hard to pick up.
You need the BEAM because operating systems we have available do not have the properties of the BEAM.
OS processes are far to heavy and slow to start, and the scheduler doesn’t work the way erlang needs it to. The BEAM solves those issues amongst others.
Also you need the BEAM for hot swapping code at runtime without taking the system offline.
To add to all these other answers, what would you hope to get out of it without BEAM? Just the syntax?
I like Python, but it's dynamically typed and slow-ish. I like Scala, but I've bumped into the pointy edges of the JVM (e.g.: type erasure) too many times. Rust is great but for most use-cases I am happy compromising with a GC than having to worry about liftimes and ownership and borrows, etc..
Gleam seems like a happy in-between for me, but not knowing much about BEAM and with my negative experiences with the JVM, I had concerns about the overhead.
I don't really have any experience with the JVM other than playing with Clojure. I don't have much to add to the other answers. Two things of note:
- BEAM trades slow CPU in favour of fast IO, so it's not great for number crunching.
- While it can be great for CLI utilities, the VM (although very lightweight) does have a noticeable startup time. It's under a second but it's not a good fit for something you would want to run often, ie, if you were building something like git.
As mentioned in other comments, its super power is its concurrency model. I've essentially forgotten what a mutex or semaphore or whatthaveyou is :)
You can try Moonbit. It's extraordinarily well designed and compiles to highly optimized JS, WASM or even native