firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

FR: Support fast local cache resolution for documents indexed by primary key

Open InputNeuron opened this issue 6 years ago • 5 comments

[REQUIRED] Describe your environment

  • Operating System version: MacOS catalina
  • Browser version: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36
  • Firebase SDK version: 7.24.0
  • Firebase Product: firestore (auth, database, storage, etc)

[REQUIRED] Describe the problem

The Firestore local cache is very very slow at resolving cache objects when there is a lot of data.

More here:

https://github.com/firebase/firebase-js-sdk/issues/2591

A lot of our queries are collection + primary key

For collections and static index lookups a simple key could be computed.

especially for collection(foo).doc('1010') lookups.

I think this should/could take you guys just a few hours to implement.

I'd bet that 50-70% of Firestore queries would fall into this category which would yield a big performance improvement.

It might also be nice to allow the user to specify a cache key so that this data is resolved from that key.

Without this we are going to implement our own workaround but that sort of defeats about 50% of the reason we're using Firestore. We're expecting you guys to do the heavy lifting here and we shouldn't have to work around bugs like this ideally.

We have one simple query that reads user prefs by primary key. The pk is the uid. The data is less than 1k.

This takes 3 seconds to resolve. That's really bad considering it's easy to build a cache key for this data.

We're pretty happy with Firestore other than this but this is a big issue for us.

InputNeuron avatar Oct 24 '20 18:10 InputNeuron

Another idea I had... maybe the cache cold be sped up by using namespaces where subsets of your cache formed a namespace.

the downside is that you would not be able to read something if it's in another cache namespace but at least it would segmented

InputNeuron avatar Oct 26 '20 16:10 InputNeuron

@burtonator Thanks for filing this. We are already optimizing our query processing for these kind of lookups (see https://github.com/firebase/firebase-js-sdk/blob/fee4e8bb7e576daeff80bde515bda1288546791e/packages/firestore/src/local/local_documents_view.ts#L165).

The processing here may be delayed because other items in our worker queue are executed beforehand. Do you think that might be the case? Firestore currently executes all cache-based operations sequentially and a query that is expensive to compute will delay all other operations.

We may also need debug logs if you cannot find an obvious culprit.

schmidt-sebastian avatar Oct 28 '20 22:10 schmidt-sebastian

Hey @burtonator. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Nov 04 '20 02:11 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@burtonator if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Nov 10 '20 02:11 google-oss-bot

@schmidt-sebastian thanks. I didn't see your comments before. I'm going to try to fix my email settings.

So I think that what you're saying is that document snapshots are probably fast BUT if they're competing with other slow queries the performance will be slow.

I think this is what we're probably seeing. The store we have is somewhat large. About 100-200MB and Firestore is super slow when dealing with the local store.

InputNeuron avatar Nov 11 '20 01:11 InputNeuron