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

Optimize snapshot cloning overhead for callbacks #1533

Closed
wants to merge 3 commits into from

Conversation

drarmstr
Copy link
Contributor

@drarmstr drarmstr commented Jan 8, 2022

Summary: If a user has a recoil callback, such as from useRecoilCallback(), and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot. Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

@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 Jan 8, 2022
@facebook-github-bot
Copy link
Contributor

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

@drarmstr drarmstr self-assigned this Jan 8, 2022
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 8, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: ccc654763404e87ad5534114767f36c2dc752f39
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 8, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: 787b7aede8979ec3a8cddff8a4c03a80b0dce6a4
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 8, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 89e1acb5f320959d6c821d7766721366772d460a
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 8, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 8539d17b7b5ac213f40480f4788d2adba6304cdd
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 8, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

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

fbshipit-source-id: f86f64c0e801c34b7af0ce89a1b141e0d193cc50
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 8, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

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

fbshipit-source-id: 06018af1f383816428f7813f0dc8585e36f280a4
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 8, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

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

fbshipit-source-id: 9d05884e9d054e2a0b68501df0f1b43ff2bb741b
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 12, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 09a8504615a71ba4be3dd4e36c1f1dfe873621e1
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: 44f0aed51e5d61701e878c3b593acff87655221a
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: e78014c0fed6e404f7debcf8fa58f5f6f94805eb
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: ed72704df156aa796478d560ab20ed456d84a73f
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: 0ff9ea37be80de272ca529fdf0da1912fb7636f2
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: 5a3bb5d54438ca3c0690d7eddb73dddb504f6845
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: b7326c6cf0d3a90565ddabca1bddd5e313e225b9
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 2c6cc370c672a6e4b016ce31d8b49eedfb1c9ce5
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: 592ac8edf75b41ab899821939a0f7231b2262474
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 39737c4ea69724939beb390089a62fdbbedadd4c
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: c1d1faa97dea0c55de7b51f93d605b015e4eaf3e
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 9080ec65b945b7fa9f53154b683ab5c055cd3338
@facebook-github-bot
Copy link
Contributor

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

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Differential Revision: D33490900

fbshipit-source-id: 0c82999b0cbf53ccea8ed61f6c44cb741ed468ce
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 13, 2022
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 41cad9a396f9b8aaabb309656775ea2f4abefe3c
@facebook-github-bot
Copy link
Contributor

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

Summary:
Pull Request resolved: facebookexperimental#1545

With us relying more on accurate snapshot retention I tracked down where we were getting warnings about using released snapshots to the RecoilDevTools `<Connector>` component.

* Properly retain the snapshot until it is used in the effect for tracking.  While snapshots are retained until an effect releases them, that auto-release effect was running before this tracking effect.
* Also cleanup the `useEffect()` to have a proper deps array and support proper cleanup and re-connecting.  Remove setting an `initialSnapshot` as it would have caused the effect to re-connect each time.  Curiously, re-connecting casuses new state changes to not appear in the dev-tools, so the `<Connector>` may not yet be compatible with `<StrictMode>`.

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

fbshipit-source-id: 5bfed7ffb938a46033445fff09d42b351cfc0daf
…tal#1546)

Summary:
Pull Request resolved: facebookexperimental#1546

Add an `isRetained()` method for Snapshots and do a safety check in `retain()` to make sure we are not trying to retain snapshots that have already been released.

Differential Revision: D33559535

fbshipit-source-id: f4560b46468f7fe9529bcbaa304d99994d9b4ef7
…l#1533)

Summary:
Pull Request resolved: facebookexperimental#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 8d69e3bf3dc7da94e64adc5d58b604ea8aea0ad2
@facebook-github-bot
Copy link
Contributor

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

@drarmstr drarmstr deleted the export-D33490900 branch January 20, 2022 22:24
AlexGuz23 pushed a commit to AlexGuz23/Recoil that referenced this pull request Nov 3, 2022
Summary:
Pull Request resolved: facebookexperimental/Recoil#1533

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

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

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

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

If a user has a recoil callback, such as from `useRecoilCallback()`, and uses it to get a snapshot many times in a loop it could incur overhead for cloning the snapshot.  Optimize this by caching the cloned snapshot and only cloning a new one if the store or state has changed.

Reviewed By: habond

Differential Revision: D33490900

fbshipit-source-id: 093b2aa498337bb2abc8eebe54a72e1a130b3469
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