If you've been around in the JavaScript UI library development space, you've likely heard about blockdom, which claims to be probably the fastest Virtual DOM that currently exists.
Its even been praised by Ryan Carniato as an example of hyper performant Virtual DOM, even being comparable to Solid.js' performance:
Blockdom is really fast
Compared with other virtual DOMs (see snabbdom, virtual-dom), it's significantly faster. These older methods use node-by-node diffing, or the traversal and comparison of the node tree in order to calculate the optimal DOM modifications to reduce reflow and repaints.
The main way that Blockdom can achieve such high performance is by performing block-by-block diffing. Why are we doing node-by-node diffing when we know most trees will be static? We have a serialized version of the block, and we can do super simple string comparisons O(1) instead of tree traversals O(n).
Old method:
[A, B, C, D] diff() [A, B, C, D]
New Method
'A,B,C,D'==='A,B,C,D'
Additionally, creating elements is much faster. Instead of individually creating elements and constructing a DOM node tree, we can just used the serialized format of the block and use the cloneNode(true) method to quickly create a DOM tree.
Here's what the syntax looks like:
// create block typesconstblock=createBlock(`<div class="some-class"><p>hello</p><blockdom-child-0/></div>`);constsubBlock=createBlock(`<span>some value: <blockdom-text-0/></span>`);// create a blockdom virtual treeconsttree=block([],[subBlock(["blockdom"])]);// mount the treemount(tree,document.body);// result:// <div class="some-class"><p>hello</p><span>some value: blockdom</span></div>
As you can see, Blockdom makes some tradeoffs in order to achieve best performance. The blockdom-child syntax is somewhat awkward, but it is necessary in order to create the block tree.
Million.js works with React and makes reconciliation faster. By using a fine-tuned, optimized virtual DOM, Million.js reduces the overhead of diffing (try it out here)
TL;DR: Imagine React components running at the speed of raw JavaScript.
Million.js intends to use the compiler to reduce computational work of diffing, and blocks are a great way to do this. Million.js forgoes the slightly awkward syntax, focusing on two main concepts: the ability to do string comparison and cloneNode(true).
This way, you don't need to construct a block and recall it every time you render. You just construct as you want, and it will handle the rest for you.
This way, it's super simple syntax without much tradeoff.
Blockdom presents exciting new ways to optimize Virtual DOM, making it a viable contender for ways we can optimize rendering in the future.
Other Virtual DOM libraries should take inspiration from Blockdom and conduct research into how block-like structures can help make Virtual DOM rendering a contender in hyper-performant rendering libraries.
Probably the fastest virtual dom library in the world!
IMPORTANT: blockdom is just a proof of concept and a place to experiment some ideas. This is
not intended to be used in a real application, no real support will be given! However, it is
designed to be the rendering engine of the Owl framework!
blockdom is a very fast virtual dom library. Its main selling
point is that it does not represent DOM element by element, but instead block by
block, where a block is an element with all its static content and some special
tags to indicate dynamic content. This allows blockdom to use cloneNode(true)
on blocks and speed up the diff process, since the vdom tree is much smaller.
It features blocks, supports fragments, manage synthetic event handlers and more
Note that it is not a framework. It does not even have the concept of components
…