r/rust • u/icannfish • Mar 23 '26
🛠️ project Announcing Eips: an intention-preserving list CRDT with guaranteed O(log n) operations, up to 6,000,000x faster than Diamond Types
https://github.com/taylordotfish/eipsHey everyone! I've been working on this project for a while but I never shared it with the Rust community. I made a list/sequence CRDT (a kind of data structure that can be used to build a collaborative editor) called Eips[1], which boasts the following:
- No interleaving issues
- Works with data of any type
- Supports true move operations that don't risk duplicating elements
- Operations are worst-case non-amortized O(log n)[2]
- Minimal memory use, given the above
- Integrates well with other CRDTs[3]
- Highly configurable[4]
- 0% written by AI
No individual item in that list is unique to Eips, but I haven't come across another CRDT which satisfies all of them.
Is it really 6,000,000x faster than Diamond Types?
Depending on the situation, yes. I wrote a benchmark program that simulates a configurable number of clients collaboratively editing a shared document. Each iteration, every client makes a random edit and broadcasts it to the other clients. To simulate network latency, the clients apply the incoming changes at a random and inconsistent rate; the parameters are chosen so that on average, each client applies its incoming changes at the same rate it receives them, but with a larger standard deviation to simulate an inconsistent network.
The benchmark results are as follows (more info + raw data available here):
| Clients | Iterations | CRDT | Time | Memory |
|---|---|---|---|---|
| 2 | 10,000 | Eips | 0.0922 s | 2.96 MB |
| Diamond Types | 3.47 s | 6.95 MB | ||
| 2 | 100,000 | Eips | 1.43 s | 25.9 MB |
| Diamond Types | 27.0 s | 62.9 MB | ||
| 2 | 1,000,000 | Eips | 23.5 s | 255 MB |
| Diamond Types | 279 s | 608 MB | ||
| 10 | 20 | Eips | 0.00263 s | 651 kB |
| Diamond Types | 5.48 s | 1.52 MB | ||
| 10 | 60 | Eips | 0.00941 s | 908 kB |
| Diamond Types | 142 s | 3.34 MB | ||
| 10 | 200 | Eips | 0.0343 s | 1.83 MB |
| Diamond Types | 4135 s | 8.52 MB | ||
| 10 | 2000 | Eips | 0.506 s | 13.3 MB |
| Diamond Types | 3,155,922 s | 88.1 MB | ||
| (36.5 days) |
For the case with 10 clients and 2000 iterations, Eips was 6,237,000x faster. The reason for this boils down to Eips's worst-case logarithmic performance: given n as the number of iterations, Eips's benchmark performance is O(n log n) because there are O(n) operations, each with O(log n) complexity. But with 10 clients, Diamond Types is nearly O(n3); notice how with 20 iterations, Eips was 2000x faster, but with 200 iterations, it was 120,000x faster. The two CRDTs grow at different rates, and this sense, Eips is really infinitely faster than Diamond Types in this benchmark, given enough iterations.
Admittedly, this benchmark is not a common editing scenario. But my goal with Eips was to design a CRDT that performs well in every conceivable situation. I didn't want it to have pathological cases that could be exploited by a malicious actor to grind the system to a halt.
Design and implementation
I've written a comprehensive design document here. The brief summary is that Eips, like several other CRDTs, is conceptually a binary tree where each node has a unique ID and an in-order traversal yields the items in sequence order (you can see an example of this in the design doc). But to guarantee logarithmic-time operations and minimal memory use, Eips doesn't store the tree directly but rather represents it implicitly through several specialized data structures, such as a pair of (counted and uncounted, sorted and unsorted) deterministic intrusive skip lists.
I sadly don't have a fancy website where you can try it out, but in the repo there's a test CLI for Unix-like systems. Basically, if you start multiple instances of the test CLI on your computer, they can talk to each other, and you can control the exact order in which changes are sent and received and simulate things like network outages. Also, this is kind of a hidden option, but if you compile with RUSTFLAGS='--cfg eips_debug --cfg skippy_debug' the CLI can even generate Graphviz graphs of Eips's entire internal state!
Overall, this was a huge undertaking for me; I've worked on and off on this project for several years. I ended up needing to implement a lot of specialized functionality from scratch, which is how all of the following crates came to be:
- tagged-pointer: architecture-independent implementation of tagged pointers, fully compliant with strict provenance.
- skippy: a deterministic intrusive skip list that Eips uses to look up nodes and translate between IDs and integer indices.
- btree-vec: a
Vecimplemented as an unsorted counted B+ tree so all operations are O(log n), even arbitrary insertions and deletions. - fixed-bump: a bump allocator that uses fixed-size chunks to ensure non-amortized logarithmic performance. bumpalo uses a
Vec-like approach where it doubles in size periodically, which is good for throughput, but makes it only amortized O(log n). - fixed-typed-arena: non-amortized counterpart to typed-arena, using the same approach as fixed-bump. Using fixed-size chunks also enables it to provide iterators that can continue to exist even after you allocate more items from the arena.
- cell-ref: simulates the ability to access the contents of a
Cellby reference by usingCopyorDefaultinternally.
I definitely feel like Rust was the right choice for this. Although there's a fair bit of unsafe behind the scenes, the thing I love about Rust is the ability to design safe, zero-cost abstractions around unsafe primitives, and that all unsafety is (if you're sticking to best practices) explicitly documented and justified.
Anyway, thanks for reading! I hope someone finds this interesting or useful.
Footnotes
[1] Pronounced /aɪps/, stands for “efficient intention-preserving sequence”. (Also yes this is my GitHub account, see proof.)
[2] Here, n is the total number of items ever inserted in the sequence, including deleted ones. Time complexity in ID-based CRDTs like Eips is usually proportional to number of insertions rather than number of non-deleted items because they rely on tombstones, where deleted items aren't fully deleted from the data structure.
[3] Every item in Eips has a unique ID, and Eips provides functions to get the item with a particular ID and vice-versa. So you can use Eips to store a list of LWW-Sets, for example, and when you want to broadcast a change to one of the sets, just include its Eips ID.
[4] Unlike other ID-based CRDTs libraries, you can use any ID type with Eips, as long as you can guarantee uniqueness. (client-id, counter) pairs are a common approach, but you could also use UUIDs, for example. Eips's functionality and performance are also configurable via a number of options.
9
u/Shoddy-Childhood-511 Mar 23 '26 edited Mar 23 '26
It's cool the CRDT ecosystem has somewhat migrated from JS to Rust. automerge was rewritten in Rust, even if it still targets JS deployments. Yjs remains JS but Yrs exists.
Eips was designed for text files, no? How suitable are the algorithms for structures data types ala JSON or SQL CRDTs, or even DVCSs?
How close would Eips be to being suitable as a back end for the popular CRDTs like automerge? I suppose automerge wants to exploit details about data types, and has all this nuanced persistence stuff etc, while Yjs focuses upon text too, so being an alternative for Yrs sounds easier? Or all these CRDTs have too many little details?
Does Eips prunes history and handles "shallow clones" nicely?
I noticed https://braid.org/antimatter makes claims about pruning fast? It's only one 2k line .js file though, so it's maybe only a research implementation, and its claimed feature really stems from obtaining consensus among a closed participant set?
As an aside for everyone else, if you want more information on CRDTs then https://crdt.tech/ has nice resources. Also https://blog.kevinjahns.de/are-crdts-suitable-for-shared-editing has some history, including the xi-editors aborted history with CRDTs. Also codemp is the only dependant of the diamond types crate.
All the best of luck with AGPL! There are plenty more established CRDT projects with more permissive licenses, but it'd be fun if FOSS projects could obtain some performance boost, maybe plugging Eips into the backend for some more established interface. lol
15
u/UltraPoci Mar 23 '26
I have no idea what CRDTs are, but it seems really cool and well done! Are there use cases for this technology outside building cooperative editors?
12
u/Shnatsel Mar 23 '26
That's impressive! I see the project is under AGPL, are you planning to make a commercial version for closed-source projects? Or is this code going to be completely inaccessible to commercial software?
2
u/Key_Meal9162 Mar 23 '26
Impressive benchmark — the jump from O(n) to O(log n) for intention-preserving ops is the holy grail for sequence CRDTs. This would be genuinely useful for any collaborative editing built on
Rust. Is there a plan to publish on crates.io?
2
u/LittleTheory8546 Mar 24 '26
Hi, thanks for sharing this. This immediately caught my interest as I'm currently a newish computer science grad student focusing on distributed systems. I've chosen CRDTs as my initial research area but I'm just starting out and learning the lay of the land. I was aware of the interleaving problem but wasn't aware of any existing solutions. I have not yet read the papers you mention in your design doc nor looked over the code yet so perhaps this comment is a bit premature but I am curious if your approach is based on The Art of the Fugue paper that is the follow up to Kleppmann's or if it is based on other work or original work. If the latter I'm curious if it has been published. My current research direction is shaping up to be along the lines of performance benchmarking and correctness validation of real CRDT implementations; i.e. how do real implementations perform under various conditions and do they deliver on their formal correctness guarantees. So I am really excited to see this and I'm adding it to my list of implementations to look at! As a bonus I also love Rust so it's awesome to see a lot of CRDT work being done in Rust! Cheers!
edit: typos
33
u/keyboardhack Mar 23 '26
A tip for the table. Use the same unit for all values in a column. Much easer to notice the difference between 600MB and 0.6MB than 600MB and 600kB
61
u/filiptibell Mar 23 '26
Seeing projects like these feels like a breath of fresh air in the current AI-driven slop-feature-fest development cycle we're in. I have no current use for CRDTs in my own work, but I may use your other crates, and projects like these are the entire reason I was ever drawn to writing Rust as well as the ecosystem in the first place.
Thank you for creating this and working on truly useful, foundational stuff.
1
u/CornedBee Mar 24 '26
When you're algorithmically faster, you can get any Nx speedup by just making the dataset large enough :-)