-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Issue Description
The main problem is that persistent query restoration takes a lot of time. For example, in this project, we have 200 poke entities, and recomputeValue takes ~80–90ms. On real projects, there might be huge objects/arrays with deeply nested data.
I think the root issue is that makeDepKey needs to iterate over every field in objects nested inside arrays, which means it fully blocks the render thread (main JS thread). This traversal becomes very expensive, and combined with the GC pressure, it slows things down significantly. In particular, the Hermes engine shows long pauses in the young generation garbage collector because of the volume of short-lived objects being created during this deep iteration.
Profiler stacktrace:
Link to Reproduction
https://github.com/IvanIhnatsiuk/apollo-cache-performance
Reproduction Steps
- Run the project.
- Uncomment the query to fetch data from the server.
- Comment out the line again.
- Re-run the project.
- Start the performance profiler.
- Click "Show Cached Data" to render SubComponentWithCachedData.
- Observe the performance degradation.
@apollo/client
version
4.0.6