Matt-Esch / virtual-dom

A Virtual DOM and diffing algorithm
MIT License
11.65k stars 780 forks source link

Big list and modify sub tree #93

Closed francescoagati closed 10 years ago

francescoagati commented 10 years ago

Hi i have aquestion. If i have a big list of 2000 elements, and i need to referesh only the class attribute of one of this element is possible to diff and patching only a subtree, without traverse all the tree. My idea is the first time to generate the tree, and for any modification of single elements mutate the state of tree without recreate it. And after pass to diff and patch only the subtree that are mutate

Raynos commented 10 years ago

It's recommended you not mutate virtual trees as that breaks certain assumptions around caching and optimizations.

There are three general performance techniques you can apply to make something like a big list faster.

As always the best recommendation is to benchmark your app and try these techniques and see what helps.

Also note that in general virtual-dom does not support subtree re-rendering. subtree re-rendering is a complex technique and has been avoided so far.

francescoagati commented 10 years ago

thanks for the reply. big list is a big problem in all libraries of virtualdom or databinding. in this case a kvo like vue.js can be more performant of a virtual dom? when is necessary rerendering a single element of the tree?

Raynos commented 10 years ago

i can't answer that without actually benchmarking it.

francescoagati commented 10 years ago

i have port the infinite scroll example of mithtil (http://lhorie.github.io/mithril-blog/an-exercise-in-awesomeness.html) in mercury. change something for mobile scroll you can see it http://codepen.io/francescoagati/pen/jDhoy

Raynos commented 10 years ago

Nice :)

francescoagati commented 10 years ago

that is the modify version of mithril. i have changed only the scroll with a continuous loop

http://codepen.io/francescoagati/pen/dyjbq?editors=001

francescoagati commented 10 years ago

@Raynos i have resolve the problem of re-rendering only a subtree element. For the initial render i process all the list, and for the sub-render i patch only the dom element that must be rerendered.

this is the example code

http://codepen.io/francescoagati/pen/xDwyE