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.

`useAtomCallback` creates a lot of atoms, resulting in performance issues

See original GitHub issue

useAtomCallback dynamically creates an atom whenever it is called, once per call site. Because of that, code with a number of components, where each component uses just a couple of callbacks, can result in a very large number of atoms being created. This appears to have a serious impact on performance.

I made a recording where I show the extent of the problem (sorry for crappy quality, I had to compress it because it was too big for Github). I also have a link to the Codesandbox I used.

https://codesandbox.io/s/demonstration-of-useatomcallback-performance-issues-29qtj?file=/src/App.tsx.

https://user-images.githubusercontent.com/10849003/128598500-a75f8984-a1f9-4da0-8f6b-5e7dd4207c84.mov

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
papermanacommented, Aug 10, 2021

@dai-shi I will try to investigate the cause of the slowness, but can’t make any specific promises right now, because I’m fairly busy with stuff. 🙁 Thank you for your work on this library, it’s very nice.

1reaction
Thisencommented, Aug 7, 2021

Not sure I see the issue tbh - It’s correct that useAtomCallback comes with a cost, because it’s additional code. It’s a way to interact with atoms imperatively.

@papermana, Can you just not use it or lift the state up, so you have the useAtomCallback in the parent component?

Read more comments on GitHub >

github_iconTop Results From Across the Web

useAtomCallback not compatible with async atoms #1345
Attempting to read async atom within useAtomCallback results in a promise being thrown: ...
Read more >
`useAtomCallback` creates a lot of atoms, resulting in ...
useAtomCallback ` creates a lot of atoms, resulting in performance issues. ... couple of callbacks, can result in a very large number of...
Read more >
useAtomCallback - Jotai
It takes a callback function that works like atom write function, and returns a function that returns a promise. The callback to pass...
Read more >
Demonstration of useAtomCallback performance issues
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >
Reagent performance issue when passing atom as a function ...
re-frame/dispatch puts your events in a queue for re-frame to process, so there can be a slightly delay before it actually goes through...
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