Cola: A text CRDT for real-time collaborative editing
nomad.foo
nomad.foo
A quite clever representation of a tree that I read about is to store nodes in DFS order in a flat array. Given that it’s read only and the readers want to traverse it depth first anyway, this can be quite efficient. S-expressions and HTML come to mind.
I’d love to see this build the rich text stuff from the Peritext algorithm.
Similar how the Pretext algorithm know that bold/italic/underlining operations are additive while highlighting colouring is not, I'm thinking the user could control the schema to declare that "state: notStarted" and "completionDate: 2023-09-04" is incompatible
You can also implement what you want at read time. "notStarted = !state.completionDate && !state.started".
Edit: Figma does this with their own server and client that intelligently handle invalid states like the parent pointers forming a loop. So it's not quite fair to say it's "just" that simple.
Technically yes; one approach would be to use a list CRDT containing representations of operations on the data structure. Each replica would play the operations forward and reject any that broke the schema to “project” the operations onto a local representation of the shared data structure.
So in your example, the operation to set state: notStarted would be rejected if a completion date were present.
Besides the fact that the computational cost of the data structure will only ever grow, another consideration is that even though you are locally only appending to the list of operations, operations from peers may arrive that are not at the end of the global order.
This approach would only guarantee that the data is consistent and meets the schema — it doesn’t guarantee that merges are semantically what a user would expect.
Couldn’t formatting be represented in the text itself the way html does it? I honestly don’t know much about other rich text representations.
Edit: the Peritext doc linked above talks out exactly these unique RTF challenges. Very interesting read.
I’d be curious to know about memory usage, too.
https://www.piumarta.com/software/cola/
https://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=91...
> This all hinges on the assumption that once we’ve inserted a node into the vector its index never changes. Inserting new nodes doesn’t cause any issues: we just append them to the end. Removing a node however would be doubly bad: not only is it a linear operation (because we’re now using a vector instead of a tree), but it would also invalidate all the indices of the nodes that come after it.
If you use my crate slotmap (https://docs.rs/slotmap/latest/slotmap/) you can support deletions without worrying about indices shifting or 'indices' (slotmap calls them keys) ever pointing at different values, as the keys in slotmap also come with a version number.
I'm not even saying that it's a particularly good fit here, especially if you wish to support undos. It's more of a future tip for when you want to use a similar pattern in a context where you really do want deletions.
Granted, that’s a lot of hash operations being redundantly computed from the same data, but it is trivial to understand and implement
If I make local edits to a document and you make remote edits to a document, the hash for your "expected state" will never match my document's state in the future because I have already made local changes.
Yes, CRDTs require all clients receive all edits in order to guarantee convergence, but the updates not needing to be applied in a certain order (which is what you are proposing) is an important property for real-world distributed use-cases.
I mean: Yes, CRDTs require all clients receive all edits in order to guarantee convergence.
They indeed do not need to be "in order", they merely need to receive all edits "to guarantee convergence". My insertion of "in order" was definitely confusing there.
https://github.com/nomad/cola - MIT licensed
From the document's first part:
> A Conflict-free Replicated Data Type, or CRDT, is an umbrella term for any data structure that can be replicated and modified concurrently across multiple sites, and is guaranteed to converge without the need for a central authority to coordinate the changes.
To be fair, the definition is not in the bulleted abstract, it is in the first use of the term in the first section, which someone not familiar with CRDT might first scan, helpfully headlined “Intro to CRDTs”:
# First part: Intro to text CRDTs
A Conflict-free Replicated Data Type, or CRDT, is an umbrella term for any data structure that can be replicated and modified concurrently across multiple sites, and is guaranteed to converge without the need for a central authority to coordinate the changes.