Performance issues when resetting a modestly sized atomFamily
See original GitHub issueI have a atomFamily, wordState
, that contains 250+ members on average. I keep track of the ‘ids’ in a separate atom, wordListState.
The user needs to be able to reset the members of wordState
back to default. I implemented this using a useRecoilCallback
which loops through the wordListState
, resetting each atom individually.
Ideally, this would be an ‘instant’ operation, however it takes anywhere from 100ms-500ms+ to complete.
Basically, wordState
contains each letter of a word. Each letter is an object with some meta information which determines how it is rendered. When the user wants to reset, we need wordListState
to have a new list of words, and each atom in the wordState
atomFamily to be reset.
You can find a minimal reproduction here, with the update time logged to the console.
This might not be the most efficient way to get the job done either, would be open to optimizations as well!
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (2 by maintainers)
Top GitHub Comments
Using an updater function with set in order to get the current value is actually the recommended way to ensure you are working with the latest value for the current React tree state. Looking at the snapshot with either
getPromise()
orgetLoadable()
(which should be a bit faster) will provide the currently committed React state when the callback was initiated.@EricPKerr I checked and it’s really the reset calls that cause the issue!