firebase-js-sdk
firebase-js-sdk copied to clipboard
Firestore: Make client-side indexing code tree-shakeable
Firestore supports a feature called "client-side indexing" (e.g. enablePersistentCacheIndexAutoCreation()) which requires a significant amount of code to support it. This feature, however, is infrequently used and causes all users of Firestore who use IndexedDb persistence to pay the code size price for this feature, even if they do not use it. According to the "Size Report" comment in this PR, the price can be as much as 23 kB.
This PR refactors Firestore so that the client-side indexing code can be tree-shaken away if not used. Namely, only the following functions will force inclusion of the client-side indexing code (otherwise it can be tree-shaken away):
enablePersistentCacheIndexAutoCreation()setIndexConfiguration()(which is deprecated and slated for deletion)
Notably, using the functions disablePersistentCacheIndexAutoCreation() and/or deleteAllPersistentCacheIndexes() will not pull in the entire client-side indexing code but, rather, only the code required to support these specific operations. This allows customers to "opt out" of client-side indexing that they had previously used without paying the code size cost of the entire client-side indexing code.
One side effect of this change is that the indexes will neither be used nor updated until the first call to either enablePersistentCacheIndexAutoCreation() or setIndexConfiguration(). Before these functions are called, or if they are never called, the indexes will neither be used nor updated. Therefore, applications are encouraged to call one of these functions early in their application, such as immediately following creating the Firestore instance, if they are used at all.
Another side effect of this change is that when using multi-tab persistence, if the tab that happens to have been elected as the "primary" tab has not called one of these functions to enable the client-side indexing functionality, then none of the tabs will get the indexes. In practice, this shouldn't be a problem because all tabs should generally be running the same version of the same app in each tab, thus all either using or not using client-side indexing.
Work In Progress
This PR is a work-in-progress. As of Jan 22, 2024, work on this PR has been de-prioritized but I'm leaving it here so it can be picked up in the future. Googlers see b/293449522 for details.
🦋 Changeset detected
Latest commit: bef8149d791a573562f66f653a5bdb398904ba4a
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 3 packages
| Name | Type |
|---|---|
| @firebase/firestore | Patch |
| firebase | Patch |
| @firebase/firestore-compat | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Size Report 1
Affected Products
@firebase/firestoreType Base (ab883d0) Merge (b35dbad) Diff browser 378 kB 380 kB +2.13 kB (+0.6%) esm5 363 kB 365 kB +1.55 kB (+0.4%) main 582 kB 585 kB +3.22 kB (+0.6%) module 378 kB 380 kB +2.13 kB (+0.6%) react-native 378 kB 380 kB +2.13 kB (+0.6%) bundleType Base (ab883d0) Merge (b35dbad) Diff firestore (CSI Auto Indexing Disable and Delete) 268 kB 245 kB -22.7 kB (-8.5%) firestore (CSI Auto Indexing Enable) 268 kB 269 kB +704 B (+0.3%) firestore (Persistence) 303 kB 280 kB -22.9 kB (-7.6%) firestore (Query Cursors) 240 kB 238 kB -1.94 kB (-0.8%) firestore (Query) 238 kB 236 kB -1.94 kB (-0.8%) firestore (Read data once) 226 kB 224 kB -1.94 kB (-0.9%) firestore (Read Write w Persistence) 322 kB 299 kB -22.9 kB (-7.1%) firestore (Realtime updates) 228 kB 226 kB -1.94 kB (-0.9%) firestore (Transaction) 205 kB 203 kB -1.94 kB (-0.9%) firestore (Write data) 205 kB 203 kB -1.94 kB (-0.9%) firebaseType Base (ab883d0) Merge (b35dbad) Diff firebase-compat.js 786 kB 763 kB -22.3 kB (-2.8%) firebase-firestore-compat.js 341 kB 319 kB -22.3 kB (-6.5%) firebase-firestore.js 437 kB 439 kB +2.07 kB (+0.5%)
Test Logs