Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize permanence calculator costs based on parameters #178

Open
katamartin opened this issue Sep 24, 2021 · 1 comment
Open

Memoize permanence calculator costs based on parameters #178

katamartin opened this issue Sep 24, 2021 · 1 comment

Comments

@katamartin
Copy link
Member

permanence-calculator-flicker

The risk parameter introduces randomness into the cost calculation, which means that when risk > 0, the cost will vary on each calculation. Because we recalculate the cost on every render, we sometimes flash different results for the same combination of parameters (e.g., on screen resizing), which might be confusing without full context.

Memoizing this calculation based on the parameters should fix this and would be a nice little UI improvement!

@blakenetz
Copy link

I have 90% of the solution in this branch:
https://github.com/blakenetz/research/tree/memoize-calculator-cost

I haven't opened a PR because it's missing one last step, which is refactoring the Curve component to prevent it from firing a set dispatch on it's initial render.

Some of the refactor was to reduce the cognitive load, but the overall approach was:

  • Refactor Cost logic into it's own context
  • Reduce side-effects by moving function definitions from the FC functional scope to the module scope
  • Add a "pristine" ref that is checked on-load, and when true, pull calculated data from local storage

I timed-box my contribution and unfortunately got pulled into something else, so I can't dedicate anymore time to this, but I wish y'all best of luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants