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

perf: call cacheKeyFn only when it is needed (if caching) #342

Merged
merged 4 commits into from
Jul 11, 2024

Conversation

abendi
Copy link
Contributor

@abendi abendi commented Jun 9, 2023

Previously cacheKeyFn was called unnecessarily with caching disabled as cacheKey was never used in such case. This PR makes sure cacheKeyFn is called only when caching is enabled and cacheKey is actually needed. Sometimes cacheKeyFn can use more expensive code, such as JSON.stringify, in which case it is preferred not to waste CPU cycles.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 9, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@saihaj saihaj requested a review from ardatan June 12, 2023 00:48
@abendi abendi changed the title perf: call and reuse cacheKeyFn only when it is needed (if caching) perf: call cacheKeyFn only when it is needed (if caching) Jun 13, 2023
@abendi
Copy link
Contributor Author

abendi commented Jul 11, 2024

Ping @saihaj, @ardatan 👀

@abendi
Copy link
Contributor Author

abendi commented Jul 11, 2024

@dimaMachina Thanks for the approval. I added a test case as well and had to fix a flow error. I don't like the usage of any in cacheMap.set((cacheKey: any), promise);. I'd prefer (cacheKey: C), but flow doesn't like that. And runtime assertion feels weird as well. Any suggestions?

@saihaj
Copy link
Member

saihaj commented Jul 11, 2024

can you please create changeset?

@saihaj saihaj merged commit 38fedd4 into graphql:main Jul 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants