infernojs / inferno

:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
https://infernojs.org
MIT License
16.09k stars 634 forks source link

Optimize static vNode trees #1413

Open Havunen opened 6 years ago

Havunen commented 6 years ago

We could detect static vNode trees during compilation time ( JSX ).

Some idea how this could work:

When static shape is detected. See https://github.com/infernojs/babel-plugin-inferno/issues/54 We hoist the given vNode tree and flag it as Static. Now during patch algorithm, when two identical vNodes are diffed we check if the shape has been marked as static we just return. This static flag could be used also to mount faster. For example when static vNode has been flagged and this vNode comes to mount routine, we check if it already contains dom, now if it returns a dom, we clone the vNode using directClone or deepClone and clone the actual DOM tree using dom.cloneNode(true). This way the whole tree can be created much faster.

This algorithm will not improve the performance for everybody, because there is usually a lot dynamic information in real single page applications, but it will benefit some apps.

farooqkz commented 1 year ago

Is this feature request still valid?

Havunen commented 1 year ago

Yep,

I tried to implement it for v8, but encountered some edge-cases which were failing.

Here is the link to inferno repo: https://github.com/infernojs/inferno/tree/static-vnode-optimization

Also babel plugin has similar branch with changes to automatically detect static trees