And that was a great trojan horse to just do a bit of performance work. So what we did is that we took this model with Zustand that called all the subscribers all the time, and instead we transitioned to atoms in which now we're finally able to just call the processing on that specific atom and be much more precise with a subscription. And to prove that this was the case, we just did a tiny sandbox, like a different repository started from scratch. And it seemed very promising, like an approach with Redux to one second for interaction, whereas an approach with Jyoti took like only 70 milliseconds, which was much, much faster. So this was definitely a success. Let's implement it. And we went and we did this giant refactor to adopt Jyoti instead of Zustand.
But then we realized we still had to keep Redux around because otherwise it would be too much of a rewrite. So we still have that to factor in. And then we realized, well, every node is not independent. We can have a node that is child of another node so that you have to update together. So we would have to write a piece of code that is able to keep track of every dependency. So no, that would have not been possible. And then we realized that some things that are actually simple, like getting the current value like transiently, or getting the value of all the nodes at the same time became too complicated. So what it turns out that we had to work around the Jyoti limitations. And after the migration, it was worse than Zustand, which was fun. So what happened is that we reverted it. But actually, no, we reverted only the Jyoti changes because, you know, when we did this giant migration, we were forced to do refactors around to adapt to this new data model. And these refactors that we did was actually extremely useful. So we managed to sell better performance with new state management library that didn't exist. And we got a nice refactor in the process which helped us immensely in the future.
How? Somebody asked inside the company a weird question, well, you know, like if a single thread that process all the data is low, what if you split the data into multiple threads and process it independently? Well, not really. But the question was, what if we split the Zustand store? Like if one store has to fire all the subscription, what if we split the store into smaller Zustand stores so that each one has its own subset of nodes and has to call less subscriptions? Well, it turns out that someone else talked about this already. And in fact, then Abramov said that it's a bad idea, unless you have performance problems. Like if you have thousands of items that are on screen at the same time, that's us. So that's exactly what we did. Let's look at how it works. First of all, we did a hash function, which, given a node, gives you what is the partition. So then we can map in a constant way, always the node to the partition. Then we create one Zustand store for each one of those partitions.
Comments