Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Optimize repeated apollo-cache-inmemory reads by caching partial query results. #3394
Reading repeatedly from
This PR is a work-in-progress with the goal of returning previous results (including nested result objects, not just the top-level result) immediately, without any unnecessary recomputation, as long as the underlying data IDs involved in the original computation have not been modified in the meantime.
This functionality is based on an npm package called
If this approach is successful, it should effectively close the performance gap between
Cache write performance should also benefit dramatically, since much of the cost of writing to the cache comes from broadcasting new results for existing queries, which requires first rereading those results from the updated cache.
Along the way, I have taken many opportunities to refactor and simplify the
I will try to add comments to the commits below to highlight areas of special interest.
I tried to give this branch a try tonight, but ran into some issues.
First, I encountered the problem I described over here: #3300 (comment)
After patching my way around this issue, I ran into an infinite recursion bug in the
I'll try to pull together a Gist with a query and payload so you can reproduce it.
Alright, here's a repro: https://gist.github.com/jamesreggio/eedd17511a3d64d1ba1613cbc08d78c5
It includes the original GraphQL document + variables, the parsed GraphQL document, the resulting data from the server, and the error.
I have a hunch that changes to
changed the title
Optimize repeated apollo-cache-inmemory reads by caching partial query results.
May 29, 2018
Jun 5, 2018
Sep 28, 2018
7 of 8 checks passed
@audiolion Good question! I have also noticed that benchmark is surprisingly slow, and honestly I haven't had a chance to dig into it. From an initial profiling, though, I can say most of the time is spent reading from the cache, apparently without much benefit from caching, rather than writing to the cache. So the solution is likely to be making sure we're making the most of the new caching system, rather than improving write performance, though I'm sure there's still room for improvement on that front as well!
All the yellow/tan/brown stuff is reading, and just the narrow violet columns are updating the cache:
The light blue / green stuff at the beginning appears to be from
Since the release, we've seen a handful of bugs that led to our removing the