inesita-rb / inesita

Frontend web application framework in Ruby using Opal.
https://inesita.fazibear.me/
MIT License
259 stars 15 forks source link

Tips for partial rendering or caching for many nodes and components #33

Closed jmstacey closed 7 years ago

jmstacey commented 7 years ago

Looking for performance tips and suggestions on component caching and efficiently interacting with the vdom/dom for a hobby I'm tinkering with.

I have a large tree of several thousand nodes I'm rendering to a nested ordered list on the page from a hash. Traversing the hash from the store only takes a few milliseconds in benchmarks, but the number of div, ol, and li vnodes created/destroyed during a render! increases the time to several hundred milliseconds before the tree is painted to the screen.

A render rate of 4 frames per second is too slow when the user is interacting with the elements--in this case dragging and dropping those elements. I'm essentially using the Draggable concern from the Web Audio Playground sample where render! is called on every mouse move.

I render a ghost of the item being dragged as well as valid drop targets in divs outside the tree with absolution positioning--i.e. the input from the store to generate the big tree does not change or need to be rendered again.

Some solutions come to mind:

...something better? Suggestions or tips on better ways to do this?

jmstacey commented 7 years ago

To speed up rendering in my case I added a should_render? lifecycle call to the component render in PR https://github.com/inesita-rb/inesita/pull/35 Basically, if should_render? is defined and returns false then the existing virtual node objects will be reused rather than creating new objects which is slow.

fazibear commented 7 years ago

It can be done with separate gem, as described in https://github.com/inesita-rb/inesita/pull/35.