In this blog post we'll design a collaborative 2D table structure using yrs - Rust port of popular yjs conflict-free replicated data types library for creating real-time, local-first apps. We'll also cover some optimizations to improve scalability of our solution.
Over the years I've often been asked if yrs is a good library for things like spreadsheets, 2D data sets etc. As usual, the answer is: it depends. Inputs can vary and depending on person big table can mean 10 000 or 1 000 000 rows. However today we'll discuss a case scenario to show that we can organize real life data set - in our case it will be Uber fares CSV which is 23MB table of total 200 000 x 9 cells - in under a second.
You can find entire demo in this Github repository. If you want to understand it better, we'll go over some design decisions and tips to optimize this particular case.
With these in mind, let's start with a word of warning: the most straightforward approach of simply mapping array of rows to ArrayRef of MapRefs. However it comes with some drawbacks: the column names are duplicated for every row, column ordering is not guaranteed etc.