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

SQL cache is unusably slow #5834

Closed
edenman opened this issue Apr 19, 2024 · 5 comments
Closed

SQL cache is unusably slow #5834

edenman opened this issue Apr 19, 2024 · 5 comments

Comments

@edenman
Copy link
Contributor

edenman commented Apr 19, 2024

Version

4.0.0-beta.4

Summary

  • New project, interacting with a old and very gnarly graphql schema.
  • Response is ~200kb
  • We're observing the cache with a CacheOnly policy and watch
  • When we make a network call, we're using NetworkOnly and then manually manipulating the response before writing it to the cache
  • When we write a response to the cache, it takes 14 seconds for the watch to fire. If I remove the SqlNormalizedCacheFactory that drops down to 3 seconds.

Steps to reproduce the behavior

        ApolloClient.Builder().apply {
            interceptors(apolloInterceptors.toList())
            networkTransport(
                HttpNetworkTransport.Builder()
                    .httpEngine(DefaultHttpEngine(okHttpClient))
                    .httpRequestComposer(RequestComposer)
                    .build(),
            )
            normalizedCache(
                MemoryCacheFactory(10 * 1024 * 1024)
                    .chain(SqlNormalizedCacheFactory("$userId-apollo.db"))
            )
            writeToCacheAsynchronously(true)
            autoPersistedQueries()
        }.build()

Logs

No response

@BoD
Copy link
Contributor

BoD commented Apr 19, 2024

Hi! Thanks for reporting.

Can you tell us a bit more about the response manipulation you're doing, and how it is done? Are you using doNotStore so that the data is not written twice to the cache? Is the writing call itself taking a while, or is it only the watch being slow to be triggered (or both).

Also in general if you could share your (or part of your) schema, query and json payload, that would help a lot to have a look and try to understand what is happening (share privately to benoit.lubek@apollographql.com if that's preferable).

@BoD BoD added 🗄️ Normalized cache ⌛ Waiting for info More information is required labels Apr 19, 2024
@edenman
Copy link
Contributor Author

edenman commented Apr 19, 2024

  • Correct, we're doing doNotStore(true) on the network query.
  • The response is a list of heterogeneous items
  • The response includes some special caching instructions in the body, so we're manually processing those and then merging the existing items with the new ones, and then inserting a new FooResponse into the cache
  • I'll send you the json payload via email

@BoD
Copy link
Contributor

BoD commented Apr 23, 2024

Thanks a lot for having shared all the details. I could reproduce writing to the cache taking an unusually long time, due to a transaction per insert being used, instead of just one transaction for all of them, when the memory cache is used with chaining. This is fixed here and will be in the next v4 release (planned in the next few days).

@BoD BoD added ✔️ Fixed in SNAPSHOTs The fix has been merged and is available in SNAPSHOTs, and will be available in the next release ✅ Fixed in v4 and removed ✔️ Fixed in SNAPSHOTs The fix has been merged and is available in SNAPSHOTs, and will be available in the next release labels Apr 23, 2024
@BoD
Copy link
Contributor

BoD commented Apr 30, 2024

Released in 3.8.4

@BoD BoD closed this as completed Apr 30, 2024
Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants