So essentially we have this tree and the dynamic values that are put in the nodes are marked as potentially, like potentially could be a value there. And so what we do now is just traverse the tree like it is usual. We check the first one as a placeholder, so on and so forth, and when we hit a placeholder, we can create something called an edit map. This is the secret sauce to the block virtual DOM.
Essentially what we say is when node 1 changes or this data changes, we change this node. Essentially we have this relational mapping between the data and the UI. And we can do this for every single placeholder node on the tree. And during runtime, the edit map really, really shines. You can see here when we're trying to update node 1 and node 2's value to 3 and 4, respectively, you can see that we only have to do two divs. So we check if the data is the same, 1, 3, yes, it has changed. Check it again, it has changed. And we can make updates to the virtual DOM. You notice here that the virtual DOM would take 5 divs, but with the block virtual DOM, it only takes 2. And this scales infinitely. This is essentially an O of 1 optimization to the virtual DOM.
And this is really cool, because we have the same example of 200 nodes on the page. Now you can see that the change is O of 1. Every single time you update, there's an O of 1 change. And it's really, really fast. So I work on a project called MillionGS. And this implements the block virtual DOM as a drop-in replacement for React. Using that, it is 30% faster than Preact, which is a lightweight React alternative, and over 70% faster than React on synthetic benchmarks. And so this is really, really indicative of better performance using the block virtual DOM, particularly on benchmarks, compared to traditional virtual DOM alternatives. And so essentially, MillionGS and the block v DOM are faster than React. And if you don't believe me, you can take a look at this example. I have a really bad computer, so bear with. When I click on this button, it's really, really red, and that's indicative of bad performance. But when I switch to Million, when it loads, if it doesn't beach ball me, you can see that when I click here, it's way better. Before it was just a plain red. It was a bloody red-like circle.
Comments