janestreet / bonsai

A library for building dynamic webapps, using Js_of_ocaml
MIT License
368 stars 39 forks source link

Are updates on every animation frame necessary? #36

Closed mooreryan closed 1 year ago

mooreryan commented 1 year ago

Semi-repost of this question on incr_dom here. Is the behavior/need to make that call on every request animation frame something fundamental to the way bonsai/incr_dom is working, or is it something that could potentially be changed/optimized? Basically, I am wondering if the ~3% scripting/cpu usage when an bonsai app is "idle" is something that you just have to live with if you're using bonsai. (Apologies as this is more of a question that a bug report.)

TyOverby commented 1 year ago

It's not fundamental to the design, and could be fixed (with some effort...) if necessary. The reasons that the loop exists are:

  1. So that time-dependent computations (like Bonsai.Clock functions) are automatically kept fresh
  2. So that changes to Bonsai.Var are automatically picked up
  3. So that changes to the model are automatically picked up

If we had an event-loop that integrated with those things, then it could schedule recomputes on demand.

mooreryan commented 1 year ago

Thanks for the info! That answers my question for now, so I will close this issue.