DEV Community

Yisar
Yisar

Posted on

Update granularity of Javascripts frameworks

Do you know that the update granularity of different Javascript frameworks is different? Let's talk about it in detail.

Coarse grained

Almost all the framework updates based on vdom are coarse-grained. The unit they update is component, and then the whole component will be re rendered for reconciliation.

Such as react, fre……

There are the advantages of vdom, but it will cause unnecessary updates. The react team says that the performance of JS runtime is negligible, so the coarse-grained update of vdom has always been a good way.

I agree with this option, because if it is not for coarse-grained update, asynchronous rendering will not be easy, and the essence of concurrent mode is repeated parallel rendering.

Fine grained

Some proxy based frameworks are fine-grained. Such as svelte, vue1. They hijack the keys of state and can update them accurately.

This is a good idea most of the time, but when there is a long list, too many proxies will be generated, and the performance will be degraded.

Block grained

This is a compromise, that is, when a block is encountered, the runtime is used for reconciliation.

Such as vue3:

<div v-for="item in items" key="item.key"/>
Enter fullscreen mode Exit fullscreen mode

output like this:

for(items, (item)=> item.key)
Enter fullscreen mode Exit fullscreen mode

The for function is a runtime function that performs internal reconciliation.

trade off

Three different granularity are good and bad, as a framework, the author should weigh the choice.

Fre uses vdom, so its updates are coarse-grained, which is more conducive to asynchronous rendering.

But I think that for frameworks like svelte, using block granularity is the best, because many algorithms are runtime optimizations.

https://github.com/yisar/fre

Finally, if you are interested in the new framework, take a look at fre.

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

Top comments (0)

DevCycle image

Ship Faster, Stay Flexible.

DevCycle is the first feature flag platform with OpenFeature built-in to every open source SDK, designed to help developers ship faster while avoiding vendor-lock in.

Start shipping

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay