1

For example, I need a timer on the page. So I can have an action every 100 ms

type Action = Tick Time

and I have field time in my Model. Model could be big, but I need to recreate it and whole view every 100 ms because of time field. I think it would not be effective performance-wise.

Is there another approach or I shouldn't worry about such thing?

ais
  • 2,514
  • 2
  • 17
  • 24

1 Answers1

1

The whole view isn't necessarily being recreated every time. Elm uses a Virtual DOM and does diffs to change only the bare minimum of the actual DOM. If large parts of your view are actually changing on every 100ms tick, then that could obviously cause problems, but I'm guessing you're only making smaller adjustments at every 100ms, and you probably have nothing to worry about. Take a look at your developer tools to see the whether the process utilization is spiking.

Your model isn't being recreated every 100ms either. There are optimizations around the underlying data structures (see this related conversation about foldp internals) that let you think in terms of immutability and pureness, but are optimized under the hood.

Community
  • 1
  • 1
Chad Gilbert
  • 36,115
  • 4
  • 89
  • 97
  • But, I guess virtual dom is recreated every Tick? About model, if I use { model | time <- x} inside update. Doesn't this statement create new model with changed time field? – ais Jan 11 '16 at 20:17
  • Isn't there also a way to optimize the diffs by using the lazy function : it caches the result of a big chunk of html and given the args, if they're same, it'll not re-render it thanks to referential transparency ? – charlysisto Jan 12 '16 at 09:45