-
Notifications
You must be signed in to change notification settings - Fork 989
Description
Describe your environment
- Operating System version: macOS 10.15.7
- Browser version: Google Chrome, Version 90.0.4430.212 (Official Build) (x86_64)
- Firebase SDK version: ^7.19.1
- Firebase Product: Firestore
Some more background that I believe is relevant:
- I use
Dexie(https://dexie.org/) to download and store binary files offline, so that my users (students) can study offline. In extreme cases, this may be up to 2Gb of data. - I have enabled persistence for users.
- I use the same query for a collection with 200 documents and collection with 18000 documents (see query below). In the current state, there is only one document with a matching id in the entire collection, so it should be easy to find . The data transfer should be low regardless, since only a single document is returned
The problem
For the "small collection" of 200 documents, the query runs in 700ms. For the "large collection" of 18000 documents, the query runs in 8000-15000ms.
Query
app
.firestore()
.collection(collection)
.where('id', '==', id)
.orderBy('updatedAt', 'desc')
.limit(1)
.get({ source: 'server' })
Theory
There is some performance issue with how the Firebase/Firestore JS SDK persists documents with regards to IndexedDB performance. For some reason, the (completely unrelated) binary data heavily affects the performance of the query as a whole.
By either clearing my local storage or disabling persistence, the query will run very quickly for the large collection as well.
Unresolved
If my theory is correct, I don't understand why the size of the queried collection matters. I have run the query against collections of various sizes and the response time jumps from 700ms to 8000+ ms once I reach a few thousand documents.
Any ideas? 🤔