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

Firestore: Make client-side indexing code tree-shakeable #7902

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Dec 22, 2023

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.

…utoCreation with deleteAllPersistentCacheIndexes
…CacheIndexes() to throw if invoked on a terminated instance
…test setup fails (merge this directly to master; it has nothing to do with CSI)
@dconeybe dconeybe self-assigned this Dec 22, 2023
Copy link

changeset-bot bot commented Dec 22, 2023

🦋 Changeset detected

Latest commit: bef8149

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 22, 2023

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (ab883d0)Merge (b35dbad)Diff
    browser378 kB380 kB+2.13 kB (+0.6%)
    esm5363 kB365 kB+1.55 kB (+0.4%)
    main582 kB585 kB+3.22 kB (+0.6%)
    module378 kB380 kB+2.13 kB (+0.6%)
    react-native378 kB380 kB+2.13 kB (+0.6%)
  • bundle

    TypeBase (ab883d0)Merge (b35dbad)Diff
    firestore (CSI Auto Indexing Disable and Delete)268 kB245 kB-22.7 kB (-8.5%)
    firestore (CSI Auto Indexing Enable)268 kB269 kB+704 B (+0.3%)
    firestore (Persistence)303 kB280 kB-22.9 kB (-7.6%)
    firestore (Query Cursors)240 kB238 kB-1.94 kB (-0.8%)
    firestore (Query)238 kB236 kB-1.94 kB (-0.8%)
    firestore (Read data once)226 kB224 kB-1.94 kB (-0.9%)
    firestore (Read Write w Persistence)322 kB299 kB-22.9 kB (-7.1%)
    firestore (Realtime updates)228 kB226 kB-1.94 kB (-0.9%)
    firestore (Transaction)205 kB203 kB-1.94 kB (-0.9%)
    firestore (Write data)205 kB203 kB-1.94 kB (-0.9%)
  • firebase

    TypeBase (ab883d0)Merge (b35dbad)Diff
    firebase-compat.js786 kB763 kB-22.3 kB (-2.8%)
    firebase-firestore-compat.js341 kB319 kB-22.3 kB (-6.5%)
    firebase-firestore.js437 kB439 kB+2.07 kB (+0.5%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/4FyhTzmQyC.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 22, 2023

Size Analysis Report 1

This report is too large (504,164 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/xNEe2dII5L.html

@dconeybe dconeybe marked this pull request as ready for review January 6, 2024 02:43
@dconeybe dconeybe requested review from a team as code owners January 6, 2024 02:43
@dconeybe dconeybe changed the title Firestore: Refactor to enable tree-shaking of client-side indexing code Firestore: Make client-side indexing code tree-shakeable Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants