bokner
InPlace is an experimental library that has implementations of several ADTs based on atomics module
In short, the ‘atomics’ API allows operations on mutable arrays of integers.
What is implemented:
- arrays
- stacks
- queues
- heaps
- priority queues
- linked lists
Check out the implementation of X algorithm by Donald Knuth, accompanied by the implementation of Sudoku as an example of usage.
X algorithm is built on the idea of Dancing Links, which relies on the modification of linked lists in place.
The implementation of Dancing Links with immutable data is usually considered to be close to impossible ![]()
Trending in Announcing
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library.
The progre...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
I’ve moved the strategies out of PowAssent and created a multi-provider framework for Elixir. This way the strategies can be used in any ...
New
Aloha gang,
There’s a new class of AI model out from TypeSafe. Jev is their flagship model. You can learn about it here:
...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
With advancements in AI gathering pace and set to increasingly accelerate, perhaps it’s worth having an annual thread on the topic - feel...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
garrison
lmao this is so unhinged I absolutely love it.
Does anyone know how the lookup from
reference => atomicis actually done internally? Is there a table, or something more clever? I feel like you could do some sort of inline caching-style trick.Schultzer
This is awesome to see, although be careful about atomics as they can be slow, I had to completely avoid them for my SOTA pool implementation as they got extremely slow due to how schedulers work in conjunction with processes that can move around freely.
If you can keep your atomics on each scheduler then you can avoid global contention.
bokner
I just found out that Donald Knuth had his birthday yesterday.
I have to say that a sizeable part of my motivation to do this project was to have more of Knuth algos in Elixir :-).
garrison
Rediscovering Erlang from first principles lol.
But they should be faster than any other way to do shared memory across cores, right? I assume you have a use-case where you want shared memory on each core but not across cores? Like the ETS
decentralized_counterstrick?Schultzer
They are indeed faster, and my first attempt with atomics was extremely fast, I only saw the issues when I had to push harder for correctness and extreme concurrency where my pool ended up allowing multiple processes to use the same connection at the same time.
So I had to lean into the BEAM for correctness which also reduced cache misses, I could properly have kept the original design and just built a queue, but it got to a place where I had to trade simplicity vs complexity.
All that being said, I want to see more of this, since we can get bare metal performance on the BEAM without writing low level code.
garrison
I’m using
:atomicsin XKS (Hobbes’s storage engine) to synchronize the LSM epoch so the readers can quickly check the current epoch from the single writer without message passing. When they’re done with an epoch they can just message the writer what epoch they’re on and it can GC old tables. I’ll write more about it soon; I think it’s pretty optimal:atomicsusage. I don’t see how anything else could be faster given that even ETS will take locks.But I am interested in mutable data structures (like the OP) because I’ve found that mixing mutable and immutable state leads to bugs. E.g. I had code that would update an ETS table and then return a new struct, and because the mental model was that of mutable state (this is a database) I on multiple occasions forgot to keep the new struct, and this caused very subtle bugs. Thankfully I have aggressive correctness tests, but it’s easier if you don’t write bugs to begin with
I try to store metadata like that in the ETS table itself now so that it can’t get out of sync.
Immutability is great for preventing bugs, but not in every situation.
Asd
Reference is literally a pointer into the memory to the refcounter. And the atomic is just a refcounted binary
garrison
Oh, that’s interesting.
References themselves are heap terms so we have to chase two pointers to get the atomic, correct? Or would that be three with the refcounting?
My understanding of the reference encoding comes from here, but it seems incomplete. I assume the atomics references take up the same space but have a pointer encoded in them? And I assume they must be tagged somehow?
Are other uses of
referenceoverloaded in this way? E.g. an ETS table ref, or monitor ref?I should really start reading the source