Skip to content

[React Native] recomputeNewValue/reallyRecompute performance issue with persistent cache #12948

@IvanIhnatsiuk

Description

@IvanIhnatsiuk

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:

Trace-20250928T234034.json

Link to Reproduction

https://github.com/IvanIhnatsiuk/apollo-cache-performance

Reproduction Steps

  1. Run the project.
  2. Uncomment the query to fetch data from the server.
  3. Comment out the line again.
  4. Re-run the project.
  5. Start the performance profiler.
  6. Click "Show Cached Data" to render SubComponentWithCachedData.
  7. Observe the performance degradation.

@apollo/client version

4.0.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions