Skip to content

Db format changes and use CacheKey in more places #108

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

Merged
merged 31 commits into from
Mar 28, 2025
Merged

Conversation

BoD
Copy link
Collaborator

@BoD BoD commented Mar 25, 2025

  • Storage binary format is changed to be a bit more compact (see RecordSerializer)
  • CacheKey (now an inline value class) is used in more APIs instead of String for consistency
  • Add ApolloStore.trim() (used to be opt-in with the blob2 format)

Also,

  • Remove ApolloCacheHeaders.EVICT_AFTER_READ - mostly to simplify the code and API
  • Same for NormalizedCache.remove(pattern: String)
  • Increase SQLite's memory cache to 8 MiB (default is 2)
  • Optim: avoid calling propagateErrors if there are no errors

@BoD BoD requested a review from martinbonnin as a code owner March 25, 2025 19:40
Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

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

A few comments but otherwise looks good!

Re: the change to CacheKey as an inline class and using it everywhere, this is a lot more typesafe but also I think this allocates more in a bunch of places?

For an example, now the cache dumps have the wrapper class everywhere, possibly other places too. Are we okay with that?

Comment on lines 45 to 46
fun serialize(): String {
return "$SERIALIZATION_TEMPLATE{$key}"
return "$SERIALIZATION_TEMPLATE{${keyToString()}}"
Copy link
Contributor

@martinbonnin martinbonnin Mar 26, 2025

Choose a reason for hiding this comment

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

You can probably remove all of the SERIALIZATION_TEMPLATE stuff now that we have a binary format that can encode CacheKey as a distinct type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is actually used by the IJ Plugin, but yes honestly this doesn't need to be here.

@BoD
Copy link
Collaborator Author

BoD commented Mar 26, 2025

For an example, now the cache dumps have the wrapper class everywhere, possibly other places too. Are we okay with that?

Good point... Not too worried about cache dumps as they're a debug thing, but there's NormalizedCache.loadRecords() and Normalizer.normalize() which are used in critical paths. I'm not sure if the additional allocations will make a difference but I can try to benchmark something to compare before/after.

@BoD
Copy link
Collaborator Author

BoD commented Mar 27, 2025

I'm not sure if the additional allocations will make a difference but I can try to benchmark something to compare before/after.

All right I've ran the read benchmarks comparing the Normalizer using Strings only vs using CacheKeys, and there was no meaningful difference.

@BoD BoD merged commit f3a2061 into main Mar 28, 2025
2 checks passed
@BoD BoD deleted the db-format-record branch March 28, 2025 09:34
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.

2 participants