LexiFi / ocaml-vdom

Elm architecture and (V)DOM for OCaml
MIT License
197 stars 13 forks source link

Throttle view and dom updates #12

Closed copy closed 6 years ago

copy commented 6 years ago

I'm writing an application that receives updates from a server very frequently. These are injected as messages using Vdom_blit.process. I noticed that Vdom_blit calls the view function very often, even multiple times per millisecond, I'm guessing after every message, which causes a high cpu usage. Instead, the view function and dom updates should be throttled, preferably using requestAnimationFrame to align with the browser's refresh rate and to avoid input lag.

As a simpler workaround, it would be useful if ocaml-vdom provided a way to send multiple messages at once, so I can queue up external messages and batch-send them myself.

alainfrisch commented 6 years ago

Thanks for the suggestion. Implemented in #14. Can you confirm that PR/branch improves the situation for your application?

copy commented 6 years ago

Thanks for the suggestion. Implemented in #14. Can you confirm that PR/branch improves the situation for your application?

Yes, this significantly improves the performance. Thanks for the quick fix!

alainfrisch commented 6 years ago

Thanks for the confirmation. Merged!