Skip to content

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

Merged
saihaj merged 4 commits intographql:mainfrom
abendi:reuse-cachekey
Jul 11, 2024
Merged

perf: call cacheKeyFn only when it is needed (if caching)#342
saihaj merged 4 commits intographql:mainfrom
abendi:reuse-cachekey

Conversation

@abendi
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Contributor Author

abendi commented Jul 11, 2024

Ping @saihaj, @ardatan 👀

@abendi
Copy link
Copy Markdown
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
Copy Markdown
Member

saihaj commented Jul 11, 2024

can you please create changeset?

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.

4 participants