Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 7427

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T03:42:12+00:00 2024-11-28T03:42:12+00:00

Exploring Blockdom: Fastest Virtual DOM (ever!)

  • 60k

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] 
Enter fullscreen mode Exit fullscreen mode

New Method

'A,B,C,D' === 'A,B,C,D' 
Enter fullscreen mode Exit fullscreen mode

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 types const block = createBlock(`<div class="some-class"><p>hello</p><blockdom-child-0/></div>`); const subBlock = createBlock(`<span>some value: <blockdom-text-0/></span>`);  // create a blockdom virtual tree const tree = block([], [subBlock(["blockdom"])]);  // mount the tree mount(tree, document.body);  // result: // <div class="some-class"><p>hello</p><span>some value: blockdom</span></div> 
Enter fullscreen mode Exit fullscreen mode

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.

You can read more about blockdom performance here

Generalized Blocks

So how can we learn from Blockdom and make existing Virtual DOM implementations better? I've been exploring this concept with Million.js.

GitHub logo aidenybai / million

Optimize React performance and make your React 70% faster in minutes, not months.

Want to automatically find and fix performance issues? Check out Million Lint.

Million.js Banner

CI NPM Version NPM Downloads

📚 Read the docs 🎦 Watch video 💬 Join our Discord 🌐 Follow on Twitter

What is Million.js?

Million.js is an extremely fast and lightweight optimizing compiler that make components up to 70% faster.

Oh man… Another /virtual dom|javascript/gi framework? I'm fine with React already, why do I need this?

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.

👉 Setup Million.js in seconds! →

Installation

The Million.js CLI will automatically install the package and configure your project for you.

npx million@latest
Enter fullscreen mode Exit fullscreen mode

Once your down, just run your project and information should show up in your command line!

Having issues installing? → View the installation guide

…
View on GitHub

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.

import { render } from 'million'; import { block } from 'million/block';  render(document.body, block('<div>Hello World</div>')); 
Enter fullscreen mode Exit fullscreen mode

You can read up about blocks in Million here.

Conclusions

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.

GitHub logo ged-odoo / blockdom

A fast virtual dom library

Open Source Love npm version Downloads

blockdom

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 …

View on GitHub

javascriptopensourcereactwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers
  • Author

    Refactoring for Efficiency: Tackling Performance Issues in Data-Heavy Pages

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.