Elixir is a functional language; its data structures are immutable. This is great for reasoning about code and supporting the massive concurrency you enjoy when you write Elixir. The double-edged sword of immutable data structures is that mutations are modeled by taking an existing data structure and an operation and creating a brand new data structure that is the result of applying that operation to the existing data structure.
Does Elixir not have an STM implementation? Looks like yes, but it’s too slow:
It tries to take advantage of persistent data structures where it can, but at the scale we operate, these large lists could not be updated fast enough.
Elixir’s built-in collections weren’t fast enough. They built a skip list of ordered sets, with the added optimization of inserting a new adjacent cell when one filled up.
They set aside a week to see if a Rust impl. could go faster:
The first benchmarks were extremely promising. The best case for adding an item to the set was 0.4𝜇s with a worst case of 2.85𝜇s, compared to OrderedSet’s 4𝜇s to 640𝜇s.
Eventually the final Rust impl. provided a 160x improvement in the worst case (6x in the best case).