This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Avoid re-rendering components if selector values don't change #749
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Nov 18, 2020
This pull request was exported from Phabricator. Differential Revision: D25040920 |
This was referenced Nov 18, 2020
…okexperimental#749) Summary: Pull Request resolved: facebookexperimental#749 An optimization that will avoid re-rendering React components if selector values they subscribe to don't change (based on reference equality). Currently, changing an atom to the same value (based on reference equality) will not propagate any downstream updates. However, any updates to a selector would propagate updates to all downstream selectors and re-render all subscribing components. This is only a partial optimization because downstream selectors will still re-evaluate. However, the React component itself will see that the final value has not changed and will suppress re-rendering. This is also only a partial fix because it only limits suppression based on reference-equality, and does not allow for a user-defined equality check. Additionally - In order to compare the new and old values before re-rendering, the subscribing component will evaluate the selector before deciding to re-render. It gets the value again during rendering, however the value will be cached in `atomValues`, so this should be cheap. By moving this evaluation earlier, it may actually help "pre-fetch" asynchronous requests before rendering starts. NOTE: This optimization is currently available under the `recoil_suppress_rerender_in_callback` GK Reviewed By: csantos42 Differential Revision: D25040920 fbshipit-source-id: 353e41cebac8566ddf7ea4de91e3790492d1178a
drarmstr
force-pushed
the
export-D25040920
branch
from
December 17, 2020 04:54
5be3060
to
655bc1a
Compare
This pull request was exported from Phabricator. Differential Revision: D25040920 |
This pull request has been merged in 13964b3. |
Note that while this diff was merged it is currently behind a feature flag. |
This was referenced Dec 29, 2020
This was referenced Jan 5, 2021
maybe related #825 |
escaton
reviewed
Feb 10, 2021
const source = useRecoilMutableSource(); | ||
const loadable = useMutableSource(source, getLoadableWithTesting, subscribe); | ||
const prevLoadableRef = useRef(loadable); | ||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drarmstr why not layoutEffect
? Postponed update of the ref could cause some propblem, don't you think?
This was referenced Mar 17, 2021
@drarmstr did this ever get released? |
AlexGuz23
pushed a commit
to AlexGuz23/Recoil
that referenced
this pull request
Nov 3, 2022
Summary: Pull Request resolved: facebookexperimental/Recoil#749 An optimization that will avoid re-rendering React components if selector values they subscribe to don't change (based on reference equality). Currently, changing an atom to the same value (based on reference equality) will not propagate any downstream updates. However, any updates to a selector would propagate updates to all downstream selectors and re-render all subscribing components. This is only a partial optimization because downstream selectors will still re-evaluate. However, the React component itself will see that the final value has not changed and will suppress re-rendering. This is also only a partial fix because it only limits suppression based on reference-equality, and does not allow for a user-defined equality check. Additionally - In order to compare the new and old values before re-rendering, the subscribing component will evaluate the selector before deciding to re-render. It gets the value again during rendering, however the value will be cached in `atomValues`, so this should be cheap. By moving this evaluation earlier, it may actually help "pre-fetch" asynchronous requests before rendering starts. NOTE: This optimization is currently available under the `recoil_suppress_rerender_in_callback` GK Reviewed By: csantos42 Differential Revision: D25040920 fbshipit-source-id: 1d49157fcc00b87bb1b3c4bee6179f5c3e3343ba
snipershooter0701
pushed a commit
to snipershooter0701/Recoil
that referenced
this pull request
Mar 5, 2023
Summary: Pull Request resolved: facebookexperimental/Recoil#749 An optimization that will avoid re-rendering React components if selector values they subscribe to don't change (based on reference equality). Currently, changing an atom to the same value (based on reference equality) will not propagate any downstream updates. However, any updates to a selector would propagate updates to all downstream selectors and re-render all subscribing components. This is only a partial optimization because downstream selectors will still re-evaluate. However, the React component itself will see that the final value has not changed and will suppress re-rendering. This is also only a partial fix because it only limits suppression based on reference-equality, and does not allow for a user-defined equality check. Additionally - In order to compare the new and old values before re-rendering, the subscribing component will evaluate the selector before deciding to re-render. It gets the value again during rendering, however the value will be cached in `atomValues`, so this should be cheap. By moving this evaluation earlier, it may actually help "pre-fetch" asynchronous requests before rendering starts. NOTE: This optimization is currently available under the `recoil_suppress_rerender_in_callback` GK Reviewed By: csantos42 Differential Revision: D25040920 fbshipit-source-id: 1d49157fcc00b87bb1b3c4bee6179f5c3e3343ba
@pthieu looks like yes - https://recoiljs.org/docs/api-reference/core/RecoilEnv/ |
eagle2722
added a commit
to eagle2722/Recoil
that referenced
this pull request
Sep 21, 2024
Summary: Pull Request resolved: facebookexperimental/Recoil#749 An optimization that will avoid re-rendering React components if selector values they subscribe to don't change (based on reference equality). Currently, changing an atom to the same value (based on reference equality) will not propagate any downstream updates. However, any updates to a selector would propagate updates to all downstream selectors and re-render all subscribing components. This is only a partial optimization because downstream selectors will still re-evaluate. However, the React component itself will see that the final value has not changed and will suppress re-rendering. This is also only a partial fix because it only limits suppression based on reference-equality, and does not allow for a user-defined equality check. Additionally - In order to compare the new and old values before re-rendering, the subscribing component will evaluate the selector before deciding to re-render. It gets the value again during rendering, however the value will be cached in `atomValues`, so this should be cheap. By moving this evaluation earlier, it may actually help "pre-fetch" asynchronous requests before rendering starts. NOTE: This optimization is currently available under the `recoil_suppress_rerender_in_callback` GK Reviewed By: csantos42 Differential Revision: D25040920 fbshipit-source-id: 1d49157fcc00b87bb1b3c4bee6179f5c3e3343ba
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Merged
performance
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
An optimization that will avoid re-rendering React components if selector values they subscribe to don't change (based on reference equality).
Currently, changing an atom to the same value (based on reference equality) will not propagate any downstream updates. However, any updates to a selector would propagate updates to all downstream selectors and re-render all subscribing components.
This is only a partial optimization because downstream selectors will still re-evaluate. However, the React component itself will see that the final value has not changed and will suppress re-rendering. This is also only a partial fix because it only limits suppression based on reference-equality, and does not allow for a user-defined equality check.
Additionally - In order to compare the new and old values before re-rendering, the subscribing component will evaluate the selector before deciding to re-render. It gets the value again during rendering, however the value will be cached in
atomValues
, so this should be cheap. By moving this evaluation earlier, it may actually help "pre-fetch" asynchronous requests before rendering starts.Differential Revision: D25040920