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

Earlier selector cache lookup #1720

Closed
wants to merge 2 commits into from

Conversation

drarmstr
Copy link
Contributor

@drarmstr drarmstr commented Apr 8, 2022

Summary:
More red lines!

While supporting some users I realized an opportunity to simplify the selector implementation slightly and optimize cache lookups to happen earlier. Previously, selectors would not cache their own value in the store state, only their dependencies. So, repeated lookups of a selector would require looking up in the more expensive selector tree cache. This optimization fixes that. It also makes Snapshot clones more robust by always cloning the TreeState to avoid snapshot selector lookup aching to inadvertently affect the parent store, which may cause atoms to skip initialization now that we are more aggresively caching.

  • Performance test of reading 100 selectors 100 times each took 1/3rd the time.
  • Performance test of reading 100 selectors with 100 dependencies 100 times each took 1/3rd the time.

Differential Revision: D35492328

…xperimental#1681)

Summary:
Pull Request resolved: facebookexperimental#1681

Minor completeness for the API to allow atoms to be initialized to `Promise` types by wrapping them, similar to atom defaults.

To properly allow Promises and such as atom values we also need the ability to set atoms to Promises.  The point of this diff is to provide completeness and for future work to support async atoms

Differential Revision: https://www.internalfb.com/diff/D34975767?entry_point=27

fbshipit-source-id: 7846112e86a9a4af82a4e76da06944ec02c9f54e
Summary:
More red lines!

While supporting some users I realized an opportunity to simplify the selector implementation slightly and optimize cache lookups to happen earlier.  Previously, selectors would not cache their own value in the store state, only their dependencies.  So, repeated lookups of a selector would require looking up in the more expensive selector tree cache.  This optimization fixes that.  It also makes `Snapshot` clones more robust by always cloning the `TreeState` to avoid snapshot selector lookup aching to inadvertently affect the parent store, which may cause atoms to skip initialization now that we are more aggresively caching.

* Performance test of reading 100 selectors 100 times each took 1/3rd the time.
* Performance test of reading 100 selectors with 100 dependencies 100 times each took 1/3rd the time.

Differential Revision: D35492328

fbshipit-source-id: 6ed71c326c78fe369cd6c73831cbf67467340343
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Apr 8, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D35492328

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Apr 8, 2022
Summary:
Pull Request resolved: facebookexperimental#1720

More red lines!

While supporting some users I realized an opportunity to simplify the selector implementation slightly and optimize cache lookups to happen earlier.  Previously, selectors would not cache their own value in the store state, only their dependencies.  So, repeated lookups of a selector would require looking up in the more expensive selector tree cache.  This optimization fixes that.  It also makes `Snapshot` clones more robust by always cloning the `TreeState` to avoid snapshot selector lookup aching to inadvertently affect the parent store, which may cause atoms to skip initialization now that we are more aggresively caching.

* Performance test of reading 100 selectors 100 times each took 1/3rd the time.
* Performance test of reading 100 selectors with 100 dependencies 100 times each took 1/3rd the time.

Differential Revision: https://www.internalfb.com/diff/D35492328?entry_point=27

fbshipit-source-id: 777d9e40ed23eb2e7ff276f489783b8f7553ddfb
@drarmstr drarmstr self-assigned this Apr 8, 2022
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Apr 12, 2022
Summary:
Pull Request resolved: facebookexperimental#1720

More red lines!

While supporting some users I realized an opportunity to simplify the selector implementation slightly and optimize cache lookups to happen earlier.  Previously, selectors would not cache their own value in the store state, only their dependencies.  So, repeated lookups of a selector would require looking up in the more expensive selector tree cache.  This optimization fixes that.  It also makes `Snapshot` clones more robust by always cloning the `TreeState` to avoid snapshot selector lookup aching to inadvertently affect the parent store, which may cause atoms to skip initialization now that we are more aggresively caching.

* Performance test of reading 100 selectors 100 times each took 1/3rd the time.
* Performance test of reading 100 selectors with 100 dependencies 100 times each took 1/3rd the time.

Differential Revision: https://www.internalfb.com/diff/D35492328?entry_point=27

fbshipit-source-id: 237e8b138d4869558b9aa8a89b795157600e9aae
@drarmstr drarmstr deleted the export-D35492328 branch June 8, 2022 20:45
AlexGuz23 pushed a commit to AlexGuz23/Recoil that referenced this pull request Nov 3, 2022
Summary:
Pull Request resolved: facebookexperimental/Recoil#1720

More red lines!

While supporting some users I realized an opportunity to simplify the selector implementation slightly and optimize cache lookups to happen earlier.  Previously, selectors would not cache their own value in the store state, only their dependencies.  So, repeated lookups of a selector would require looking up in the more expensive selector tree cache.  This optimization fixes that.  It also makes `Snapshot` clones more robust by always cloning the `TreeState` to avoid snapshot selector lookup aching to inadvertently affect the parent store, which may cause atoms to skip initialization now that we are more aggresively caching.

* Performance test of reading 100 selectors 100 times each took 1/3rd the time.
* Performance test of reading 100 selectors with 100 dependencies 100 times each took 1/3rd the time.

Reviewed By: noritheduck

Differential Revision: D35492328

fbshipit-source-id: 89547b97a7f61b03153cf3afe366a6f47ef22e52
snipershooter0701 pushed a commit to snipershooter0701/Recoil that referenced this pull request Mar 5, 2023
Summary:
Pull Request resolved: facebookexperimental/Recoil#1720

More red lines!

While supporting some users I realized an opportunity to simplify the selector implementation slightly and optimize cache lookups to happen earlier.  Previously, selectors would not cache their own value in the store state, only their dependencies.  So, repeated lookups of a selector would require looking up in the more expensive selector tree cache.  This optimization fixes that.  It also makes `Snapshot` clones more robust by always cloning the `TreeState` to avoid snapshot selector lookup aching to inadvertently affect the parent store, which may cause atoms to skip initialization now that we are more aggresively caching.

* Performance test of reading 100 selectors 100 times each took 1/3rd the time.
* Performance test of reading 100 selectors with 100 dependencies 100 times each took 1/3rd the time.

Reviewed By: noritheduck

Differential Revision: D35492328

fbshipit-source-id: 89547b97a7f61b03153cf3afe366a6f47ef22e52
eagle2722 added a commit to eagle2722/Recoil that referenced this pull request Sep 21, 2024
Summary:
Pull Request resolved: facebookexperimental/Recoil#1720

More red lines!

While supporting some users I realized an opportunity to simplify the selector implementation slightly and optimize cache lookups to happen earlier.  Previously, selectors would not cache their own value in the store state, only their dependencies.  So, repeated lookups of a selector would require looking up in the more expensive selector tree cache.  This optimization fixes that.  It also makes `Snapshot` clones more robust by always cloning the `TreeState` to avoid snapshot selector lookup aching to inadvertently affect the parent store, which may cause atoms to skip initialization now that we are more aggresively caching.

* Performance test of reading 100 selectors 100 times each took 1/3rd the time.
* Performance test of reading 100 selectors with 100 dependencies 100 times each took 1/3rd the time.

Reviewed By: noritheduck

Differential Revision: D35492328

fbshipit-source-id: 89547b97a7f61b03153cf3afe366a6f47ef22e52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants