You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using cache.modify to change a field on a single item in a large hierarchical data structure is consistently fast (a fixed ~40ms) until the dataset reaches some threshold number of items (some tens of thousands in our case), at which point there appears to be a change of behavior which results in the action taking much longer (from ~40ms in the case of 10K items to ~440ms in the case of 20K items).
Patching the optimism module (@benjamn) used by Apollo Client to use Infinity (or some other large number) for Cache.max makes the operation fast again.
I would be interested to know if:
there is something we are doing which is inadvertently triggering this behavior,
if the patch could have unintended consequences (memory usage?),
if this cache size parameter is something that could be configurable via Apollo Client.
Detail:
We have a hierarchical data structure (with a fixed maximum depth when queried) of this approximate shape:
We render the associated data in a virtualized tree component, no more than twenty items at once.
With 10,000 items in the tree, we see the modification take ~40ms, with this stack trace:
With 20,000 items in the tree, we see the modification take ~440ms, with this stack trace (profile before this branching is similar to the previous one, I can provide full if helpful):
The patch we make to the optimism module is (I guess equivalent would be to pass the max parameter whenever Apollo Client uses wrap):
functionwrap(originalFunction,options){if(options===void0){options=Object.create(null);}// Old: // var cache = new Cache(options.max || Math.pow(2, 16), function (entry) { return entry.dispose(); });// New:varcache=newCache(Infinity,function(entry){returnentry.dispose();});
With this in place, the performance drop-off is not seen and modification is back to the order of tens of milliseconds (even with +50K items).
We use the default InMemoryCache, have assumeImmutableResults: true, and are on Apollo Client 3.3.6.
We've tried Apollo Client 3.4.0-beta.4 and see the same issue.
If we have broadcast: false in the call to cache.modify, we don't see the performance issue.
Our setup is fairly complex but I can attempt a reproduction if helpful.
Thanks for the library and all the hard work on AC3, have found it a great tool.
@acton-bell Thanks for digging all the way down to this level of the implementation. I'm open to making the default cache size limit configurable, though I'd like to do some performance testing to make sure there's not a simpler solution (like postponing the cleanup to happen asynchronously, or something like that).
Your patch to use Infinity definitely should be safe, in the meantime.
Summary:
Using
cache.modify
to change a field on a single item in a large hierarchical data structure is consistently fast (a fixed ~40ms) until the dataset reaches some threshold number of items (some tens of thousands in our case), at which point there appears to be a change of behavior which results in the action taking much longer (from ~40ms in the case of 10K items to ~440ms in the case of 20K items).Patching the
optimism
module (@benjamn) used by Apollo Client to useInfinity
(or some other large number) forCache.max
makes the operation fast again.I would be interested to know if:
Detail:
We have a hierarchical data structure (with a fixed maximum depth when queried) of this approximate shape:
We use
cache.modify
to change the value ofisSelected
:We render the associated data in a virtualized tree component, no more than twenty items at once.
With 10,000 items in the tree, we see the modification take ~40ms, with this stack trace:

With 20,000 items in the tree, we see the modification take ~440ms, with this stack trace (profile before this branching is similar to the previous one, I can provide full if helpful):

The patch we make to the
optimism
module is (I guess equivalent would be to pass themax
parameter whenever Apollo Client uses wrap):With this in place, the performance drop-off is not seen and modification is back to the order of tens of milliseconds (even with +50K items).
We use the default InMemoryCache, have
assumeImmutableResults: true
, and are on Apollo Client 3.3.6.We've tried Apollo Client 3.4.0-beta.4 and see the same issue.
If we have
broadcast: false
in the call tocache.modify
, we don't see the performance issue.Our setup is fairly complex but I can attempt a reproduction if helpful.
Thanks for the library and all the hard work on AC3, have found it a great tool.
Versions
The text was updated successfully, but these errors were encountered: