Replies: 1 comment
-
|
500ms-1000ms for observer creation is definitely not expected. With 465+ queries and 30+ active fetches, here are some things to investigate: 1. Profile the exact operation const start = performance.now();
const result = useQuery(...);
console.log("useQuery took:", performance.now() - start);2. Check if it's React DevTools 3. Subscription overhead // Check how many observers exist
console.log(queryClient.getQueryCache().getAll().reduce(
(sum, q) => sum + q.observers.length, 0
));4. Possible culprits
5. Try isolating // Minimal reproduction
const testQuery = useQuery({
queryKey: ["test", Date.now()],
queryFn: () => Promise.resolve(null),
enabled: false,
});If this minimal query is also slow, it's likely cache size related. If fast, then something in your options is expensive. 6. Consider query client config new QueryClient({
defaultOptions: {
queries: {
structuralSharing: false, // Try disabling if you have large data
},
},
});A cache with 465+ entries shouldn't cause 500ms delays, so something else is likely at play. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
We're experiencing a consistent 500-1000ms delay the first time we call
useQuery()for a specific query key (and only the first time for each new query key), even before any network request is initiated.Is setting up the observer and cache for an individual query supposed to be this expensive?
Observed Behaviour
We have an app that changes an "activeConversationId". Every time this conversationId changes, a 500ms block occurs on react query.
3a. The 500ms occurs BEFORE the network request starts
['simple', id]- still slow Bypassed tRPC'squeryOptions()- still slowgetQueryData()calls are instant (~1ms)Environment
Question
Is this 500ms delay expected behavior when creating queries with new keys in a cache of this size? What am I doing wrong here?
Beta Was this translation helpful? Give feedback.
All reactions