This is a sample app to reproduce issue
#7295 in the
firebase-android-sdk: "Firestore cache query slow when cache filled with deleted documents".
This project can be used to demonstrate the performance issue and to test the corresponding fix.
Before you begin, ensure you have the following tools installed:
- Android Studio: For building and running the Android application.
- Node.js: Version 20 or newer (for running the Firebase CLI).
- Git: For cloning the SDK repository to test the fix.
These steps will guide you through running the app against a public version of the Firestore SDK to see the slow query performance.
You must have the Firebase CLI installed. The emulator will be started with a placeholder project ID, so no cloud project is required.
# Install Firebase Tools globally
npm install -g firebase-tools
# Start the Firestore emulator
firebase emulators:start --only firestore --project prjh5zbv64sv6- Open this project directory in Android Studio.
- Change the build variant to release (optional, but this gives more meaningful performance numbers).
- Run the app on a device or emulator.
The first time the app runs, it will create and then delete 10,000 documents. This populates the local Firestore cache with "tombstone" entries that cause the performance issue. Subsequent runs will skip this "setup" step and execute two sets of queries 200 times each: one against a non-existent collection and one against the collection with the deleted documents. The performance difference will be printed to the UI of the application.
These steps will guide you through building the Firestore SDK with the fix, publishing it to your local Maven repository, and running the app against that local version.
The fix is contained in pull request #7301.
To properly test the fix, you must first run the app without the fix to populate the cache with the problematic data.
- If run have run the app before, uninstall it to ensure the next run starts with a clean state.
You can do so by running
adb shell pm uninstall com.example.firebaselocalsample - Ensure
app/build.gradle.ktsuses a public version of the Firestore SDK without the fix (e.g.,com.google.firebase:firebase-firestore:26.0.0). - Follow the steps in "Part 1" to run the app once.
-
Clone the
firebase-android-sdkrepository:git clone https://github.com/firebase/firebase-android-sdk.git cd firebase-android-sdk -
(Optional as of Sept 08, 2025, as the fix was merged into the main branch) Fetch the pull request containing the fix and check it out.
git fetch origin pull/7301/head:PR7301_NoDocumentPerformanceFix git checkout PR7301_NoDocumentPerformanceFix
-
Edit
firebase-firestore/gradle.propertiesand change the version to99.99.99. Using a high, non-existent version number such as99.99.99ensures that Gradle will resolve this dependency to your local build instead of a public version from a public maven repository. -
Publish the modified Firestore SDK to your local Maven repository.
./gradlew :firebase-firestore:publishToMavenLocal
-
Back in this sample app project, edit
settings.gradle.ktsand addmavenLocal()to thedependencyResolutionManagement.repositoriesblock. This tells Gradle to look for dependencies in your local Maven repository.dependencyResolutionManagement { repositories { google() mavenCentral() mavenLocal() // Add this line } } -
In
app/build.gradle.kts, change the version of thecom.google.firebase:firebase-firestoredependency to99.99.99.dependencies { implementation("com.google.firebase:firebase-firestore:99.99.99") // ... other dependencies } -
Compile and run the app. It will now use the locally-built SDK. Observe the query times reported in the app's UI and compare them to the results from Part 1. The queries on the collection with deleted documents should now be significantly faster.