question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issues when resetting a modestly sized atomFamily

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
drarmstrcommented, Aug 21, 2020

Yep I ran to a similar issue where an atom with 20 - 30 objects, was taking ~1 second when using await snapshot.getPromise(atom) found that instead using a set function to get the current value (set(atom, (current) => ....)) worked much better. Not sure if this has any stale data implications but in my case it wasn’t the end of the world if that was the case

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() or getLoadable() (which should be a bit faster) will provide the currently committed React state when the callback was initiated.

1reaction
manyopensourcecommented, Aug 21, 2020

@EricPKerr I checked and it’s really the reset calls that cause the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

atomFamily(options) - Recoil
Returns a function that returns a writeable RecoilState atom.
Read more >
In-Depth Review: Gigabyte's J1800N-D2H Mini-ITX Motherboard
The low-budget, low-power, low-performance Intel Atom family, ... Meanwhile, the J1800 packs a downsized version of Intel's Gen7 graphics core, ...
Read more >
ACS Applied Materials & Interfaces | Vol 14, No 48
In this issue: Biological and Medical Applications of Materials and Interfaces; Energy, Environmental, and Catalysis Applications ...
Read more >
Gracemont Microarchitecture (E-Core) Examined - Intel Architecture ...
It forms part of Intel's Atom family of processors, and is a significant microarchitectural jump over the previous Atom core design called Tremont....
Read more >
Basic Research Needs for Carbon Capture: Beyond 2020
carbon capture problem is looked at closely, we see today's technologies fall far short of ... A modest-sized 500 MW power plant produces...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found