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

Use cached value in derived atom watcher #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidwalker
Copy link

This change avoids recalculating old-value using the selector fn if cache already contains the correct value. For expensive selector functions this can have a big impact on performance.

It uses the same code as is used in -deref to establish validity of the cached value.

I saw there was previously code which attempted to use the cache in watchers but it was removed in df32b5a with a comment that it caused race conditions in some situations.

I think there were two issues with the previous code that aren't present in this change:

  1. it used queueMicroTask which introduces a delay which could result in a race condition.
  2. it didn't check that the srccache value matched the old-source-value which could result in an incorrect cache value being used.

Avoids recalculating the previous value using selector if the cache
already contains the correct value.

Uses the same code as -deref to establish validity of cache value.
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

Successfully merging this pull request may close these issues.

1 participant