-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
🔥 Firestore getDocs() Takes 25+ Seconds on Android
Issue
Firestore queries with getDocs() are taking 25-53 seconds to return just 2 documents on Android. The delay is in the SDK call itself, not in data processing. Performance is inconsistent and unpredictable.
Query Code
import { collection, query, where, orderBy, limit, getDocs } from '@react-native-firebase/firestore';
const collectionRef = collection(db, 'clients/{clientId}/branches/{branchId}/orders');
const constraints = [
where('isPaid', '==', true),
where('order_date', '>=', startDate),
where('order_date', '<=', endDate),
orderBy('order_date', 'desc'),
limit(9)
];
const q = query(collectionRef, ...constraints);
console.time('getDocs');
const snapshot = await getDocs(q); // Takes 25+ seconds!
console.timeEnd('getDocs');Performance Metrics
⏱️ getDocs: 25,991ms (26 seconds!)
📊 Returned: 2 documents
Observed timings on different executions:
- First query: 53 seconds, returned 0 documents
- Second query: 26 seconds, returned 2 documents
- Third query: 377ms, returned 1 document (occasionally fast)
What We've Ruled Out
✅ No composite index errors in Firebase Console
✅ Not a data processing issue (processing takes < 5ms)
✅ Not a network issue (other Firebase operations are fast)
✅ Query is simple (1 equality filter + 1 range filter + orderBy)
Steps to Reproduce
- Configure Firestore with persistence enabled and large cache size (see firebase.json below)
- Execute a query with multiple where clauses + orderBy + limit
- Measure time taken by
getDocs() - Observe 20-50+ second delays inconsistently
Expected Behavior
Query should complete in < 500ms
Actual Behavior
Query takes 25-53 seconds inconsistently, sometimes fast (~377ms), making the behavior unpredictable.
Additionally, sometimes a simple setDoc() with a single field takes 20+
seconds, while normally it completes in less than 500ms.
Project Files
Javascript
Click To Expand
package.json:
{
"dependencies": {
"react": "19.1.0",
"react-native": "0.80.2",
"@react-native-firebase/app": "^23.8.6",
"@react-native-firebase/firestore": "^23.8.6",
"@tanstack/react-query": "^5.56.2"
}
}firebase.json for react-native-firebase v6:
{
"react-native": {
"firestore_settings": {
"persistence": true,
"cache_size_bytes": 524288000,
"ignore_undefined_properties": true
}
}
}iOS
Click To Expand
ios/Podfile:
- I'm not using Pods / Not tested on iOS yet
- I'm using Pods and my Podfile looks like:
# N/AAppDelegate.m:
// N/AAndroid
Click To Expand
Have you converted to AndroidX?
- my application is an AndroidX application?
- I am using
android/gradle.settingsjetifier=truefor Android compatibility? - I am using the NPM package
jetifierfor react-native compatibility?
android/build.gradle:
// Standard RN 0.80.2 configurationandroid/app/build.gradle:
// Standard RN 0.80.2 configuration with Firebase dependenciesandroid/settings.gradle:
// N/AMainApplication.java:
// Standard RN setupAndroidManifest.xml:
<!-- Standard RN setup -->Environment
Click To Expand
react-native info output:
System:
OS: Windows
Node: v18.x
npm: v9.x
React Native:
react-native: 0.80.2
react: 19.1.0
- Platform that you're experiencing the issue on:
- iOS
- Android
- iOS but have not tested behavior on Android
- Android but have not tested behavior on iOS
- Both
react-native-firebaseversion you're using that has this issue:23.8.6
Firebasemodule(s) you're using that has the issue:@react-native-firebase/firestore
- Are you using
TypeScript?Yes&5.x
Additional Questions
- Is this a known issue with persistence enabled on Android?
- Should
cache_size_bytes: 524288000(500MB) be reduced for better performance? - Any recommended Firestore settings for Android performance optimization?