Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform all DocumentNode transforms once, and cache the results. #4601

Merged
merged 4 commits into from
Mar 22, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Mar 18, 2019

Much of this work was previously duplicated for every request, which was not only wasteful for obvious reasons, but also limited the benefits of caching based on DocumentNode references, since repeatedly transforming the same document changes its referential identity, making it hard to tell whether a given document has been encountered before.

Much of this work was previously duplicated for every request, which was
not only wasteful for obvious reasons, but also limited the benefits of
caching based on DocumentNode references, since repeatedly transforming
the same document changes its referential identity, making it hard to tell
whether a given document has been encountered before.
@benjamn benjamn added this to the Release 2.6.0 milestone Mar 18, 2019
@benjamn benjamn self-assigned this Mar 18, 2019
@benjamn benjamn requested a review from hwillson March 18, 2019 23:52
@@ -689,6 +682,63 @@ export class QueryManager<TStore> {
};
}

private transformCache = new WeakMap<DocumentNode, Readonly<{
Copy link
Member Author

@benjamn benjamn Mar 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had to stop using WeakMap in #3394 because the React Native Android polyfill for WeakMap is especially broken, so I think we may need to find a way to use a Map here instead, ideally only when running in React Native. I'll work on that tomorrow.

Map should be fine for the purposes of this code. In fact, caching the transforms in a consolidated way probably has a bigger memory impact than using a WeakMap.

@benjamn benjamn merged commit 9dd53fc into release-2.6.0 Mar 22, 2019
@benjamn benjamn deleted the cache-document-transforms branch March 22, 2019 17:45
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant