Skip to content
Source
Sign inSign up
TanStack/query

Solid: bad `useQuery` performance when creating a lot of elements #9864

Send to my agent
Closedteidesu(GitHub profile, opens in a new tab) opened this issue 4 comments

Describe 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.

Image

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-bcmxksoc?file=src%2Findex.tsx,src%2FApp.tsx&terminal=dev

Steps to reproduce

  1. open the reproduction
  2. click "show many"
  3. 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

  1. @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

  2. @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 getQueryData call (available by adding #sync=1 to the url) for comparison, which performs much better: INP ~130ms vs ~550ms

    my main point being that using useQuery shouldn't make rendering 4 times slower 😭

    Trace-20251128T015918.json.gz

  3. hey @TkDodo is this relevant? I can take it on me :) Thanks

  4. my main point being that using useQuery shouldn't make rendering 4 times slower 😭

    well useQuery does a lot of things: it creates observers, subscribes to the cache for updates and creates timers (which can be expensive).

    Comparing it to getQueryData is 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: Infinity too 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.

  5. TkDodo closed this

  6. TkDodo added labelswontfix

  7. TkDodo added labelsworks as designed

Sign in to join this conversation.