Description Link : https://2a7.notion.site/Performance-Report-880f12da5d054c27b2644ef887790d7f?pvs=4
I've been analyzing the performance of an application using Apollo Client for GraphQL queries and noticed some significant changes in response times. I followed a systematic approach to measure the performance, alternating between tests and using Incognito Mode with cleared cache and hard refresh for each measurement.
Before making any improvements, I used router.push for navigation, which resulted in response times of 7.68 seconds, 5.85 seconds, and 6.38 seconds respectively. After implementing improvements by using useContext, the response times were reduced to 4.68 seconds, 4.5 seconds, and 5.16 seconds.
This change led to an average improvement of 1.85 seconds. In particular, the time from the loading page to the Largest Contentful Paint (LCP) completion showed a 2-second difference, dropping from 2.5 seconds to just 0.5 seconds post-improvement.
Further analysis indicated that the query calls were the primary cause of delay, showing a difference of 1.97 seconds. The query calls took 2 seconds before improvements and just 300 milliseconds after.
However, repeated measurements and Network tab checks revealed inconsistencies in query response times, even though the same queries were called. Before the improvement, query response times were around 2.24 seconds, while after the improvement, they dropped to 0.32 seconds.
Could the use of query parameters in Apollo Client be contributing to this slowdown? I'm curious if there's a known correlation between query parameter usage in Apollo Client and these observed performance variations.
I'm not sure what you mean by query parameters, as the screenshots don't indicate the use of url query parameters before or after.
What I see is that you're using the BatchHttpLink
though. While generally that minimizes the number of requests, it also means that on the server a response is only sent after all batched requests have fully been processed - if one of these queries is slow, it will slow all the others down. It might be worth a try with a normal HttpLink for initial page load.