Derived state performance #1381
Unanswered
PierreCapo
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You could make custom setters or property observers on the dependencies and a private setter on the the result.
You still have to manually update the state but at least it's done in a single place, transparent to reducers |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes we want some state value to derive from other ones, but I can not find the correct approach in case of performance issues.
❌ Problem:
pointsOfInterests
gets recalculated every time it is accessed by the UI. I am working on a scenario with a map, so the UI is refreshed continuously whenever the user drag the map, meaning thatpointOfInterest
as a computed property is evaluated a lot of time and makes the app lag.❌ Problem: It fixes the performance issue because
pointsOfInterests
is only recomputed whendata
orsomeFilters
changes. However this introduce a cohesion issue where you need to not forget to updatepointsOfInterests
when you updatedata
orsomeFilters
which is not scalable in the long-term run.My question: What is the pattern to only recompute a derived state only when its dependencies change to avoid performance issues ?
With a more familiar approach a bit a la Combine:
pointOfInterests
is only recomputed when its "dependencies" change and keep the cohesion integrity in the code 👍Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions