Skip to content

Conversation

@david-crespo
Copy link
Collaborator

@david-crespo david-crespo commented Oct 16, 2024

Closes #2270

Reduce gcTime on upload chunk React Query mutation from default of 5 minutes to zero.

As I say in the comment, I don't even understand why the mutation cache exists — it's not like we're reading from it. The query cache is a different story. So I don't see a downside to turning it off for this mutation. I have asked about in the Tanstack Discord and on Twitter, so I'll see if anything helpful comes out of that.

https://tanstack.com/query/v5/docs/reference/MutationCache
https://tanstack.com/query/v5/docs/framework/react/reference/useMutation
https://tkdodo.eu/blog/mastering-mutations-in-react-query

Before

Taking some snapshots in FF throughout a big upload. Memory goes up and up.

Screenshot 2024-10-15 at 3 58 10 PM

After

Memory fluctuates around a relatively small value, consistent with GC functioning as desired.

image

With shorter but non-zero gcTime

As a test, I set gcTime: 60000 (1 minute) and saw as expected that memory use still plateaus, but at a higher number because it holds onto everything it can process in one minute.

image

@vercel
Copy link

vercel bot commented Oct 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Oct 16, 2024 4:41pm

@david-crespo
Copy link
Collaborator Author

I can't see a downside here, so I'm going to just merge this. If we learn something new we have plenty of time to revert before the next release.

@david-crespo
Copy link
Collaborator Author

david-crespo commented Oct 17, 2024

I think we're in the clear. We don't need these mutations in any cache. We might not need any mutations in the cache, but we can think about that another time. The idea of using useMutationState to see whether a mutation is pending or errored or whatever without having to pass the original mutation object around is pretty cool, though.

image

https://x.com/TkDodo/status/1846779928768836033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate: image upload consumes a lot of memory

2 participants