Firestore: Make client-side indexing code tree-shakeable#7902
Open
Firestore: Make client-side indexing code tree-shakeable#7902
Conversation
🦋 Changeset detectedLatest commit: bef8149 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Collaborator
Size Report 1Affected Products
Test Logs |
Collaborator
Size Analysis Report 1This 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 |
…NCE_MEMORY_DB env var in tests)
…: fix spurious errors on test cleanup)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/ordeleteAllPersistentCacheIndexes()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()orsetIndexConfiguration(). 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 theFirestoreinstance, 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.