Solid: bad `useQuery` performance when creating a lot of elements #9864
Send to my agentDescribe the bug#
creating a lot of elements at once leads to ui stutters due to useQuery taking up to 4-5ms. even if there's already data cached and refetching is disabled.
Your minimal, reproducible example#
https://stackblitz.com/edit/vitejs-vite-bcmxksoc?file=src%2Findex.tsx,src%2FApp.tsx&terminal=dev
Steps to reproduce#
- open the reproduction
- click "show many"
- notice how the ui freezes for a while
Expected behavior#
as a user, i expect useQuery to not block rendering so much, especially when there's already data in the cache
How often does this bug happen?#
None
Screenshots or Videos#
https://github.com/user-attachments/assets/894528f6-111c-45a9-a965-46e4bbf4f809
Platform#
- OS: macOS (M3 Max)
- Browser: Chrome 141
- Version: 5.90.10, Solid 1.9.10
Tanstack Query adapter#
solid-query
TanStack Query version#
5.90.10
TypeScript version#
5.9.3
Additional context#
No response
@marustas even on your recording it's visible how clicking the "show more" button makes the browser drop a few frames :c
just re-tested on m3 max, the issue is indeed for some reason less apparent than on the original recording, so i bumped the number of items to 5k for it to be more visible.
also added an "alternative" version with manual
getQueryDatacall (available by adding#sync=1to the url) for comparison, which performs much better: INP ~130ms vs ~550msmy main point being that using
useQueryshouldn't make rendering 4 times slower 😭hey @TkDodo is this relevant? I can take it on me :) Thanks
my main point being that using useQuery shouldn't make rendering 4 times slower 😭
well
useQuerydoes a lot of things: it creates observers, subscribes to the cache for updates and creates timers (which can be expensive).Comparing it to
getQueryDatais apples and oranges because that’s just a one-time read that isn’t reactive.profiling shows timeouts as the main culprit, so you might want to either set
gcTime: Infinitytoo to avoid having a timer, or you set your own timeoutManager and implement a timer-wheel to batch some of those.but yes, creating 5k observers at the same time will have an overhead. We usually draw the line at 1k. Anything more you have to get creative to not feel it.
TkDodo closed this
TkDodo added labelswontfix
TkDodo added labelsworks as designed
Sign in to join this conversation.
@teidesu Hey! I ran your code on a Macbook M4 Pro, no lag in rendering. Maybe the issue is with your specific environment? Below's the screen recording of the run. https://github.com/user-attachments/assets/d2b5169f-24ee-463c-91e9-be6c6253cfc1