relay-tools / relay-hooks

Use Relay as React hooks
https://relay-tools.github.io/relay-hooks/docs/relay-hooks.html
MIT License
542 stars 56 forks source link

[proposal] Optimize cache reads by opting out of data checker. #262

Closed Lalitha-Iyer closed 10 months ago

Lalitha-Iyer commented 11 months ago

@morrys I want to thank you for the amazing support you provide for this repository. I have a proposal which I believe could be generally useful to the community. Let me know what you think.

Proposal

Provide a query option to opt-out of Data checking when reading fully cached queries.

Context.

While using Relay in our application, we noticed that the relay-runtime's Datachecker is a bottleneck for some of our complex queries and can cause the read latency to be as high as ~15-20ms.

We also realized our application doesn't rely on all of the use-case for which DataChecker was designed. The only use-case that is relevant to us is populating missing fields, when the data checker runs.

When we tried a patch with this change, we roughly see 20% improvement in cache read times for fully cached queries.

morrys commented 11 months ago

Hi @Lalitha-Iyer, another task of the datacheck is to check if the store or one of its records is not invalidated (https://relay.dev/docs/api-reference/store/#invalidatestore-void)

I have some doubts about modifying this logic, perhaps we could think about the possibility of configuring custom management of the lookupInStore function

Have you tried opening an issue in the official relay due to the check latency problem?

Lalitha-Iyer commented 10 months ago

Thanks @morrys I will open an issue with the relay team about Datachecker slowness. After testing I also realized Datachecker is necessary when using fragment arguments, it validates if fragment arguments have changed. I still think it might be useful to provide an option at the query level to opt-out, for expensive queries. But we can revisit this later.