Repository navigation
[🐛] 🔥 Slowness using complex queries #8538
Description
Issue
We are experiencing significant performance issues with Firestore queries that includes a where clause on a any fields (e.g., order_date) with or without a bounded range (>= and/or <=). Despite all required indexes being created and the result set being small or empty, the query consistently takes ~9 seconds to return. This happened to us only after upgrading the package to the latest version.
NOTE: We tried using the Firebase Web SDK and it takes significantly less time to load. using firebase version 11.6.1. However, we need the offline persistence, so we cannot migrate to the web sdk.
UPDATE: We tried to downgrade to @react-native-firebase/firestore version ^21.6.1 and it worked perfectly fine.
-- version 22.2.0 -- this takes 20.59511 seconds:
const path = `clients/{clientId}/branches/{branchId}/orders`;
const ref = collection(db, path);
const q = query(ref, where("isPaid","==",false), where("isVoid","==",false), where("order_status_id","==","new-order"), orderBy("order_date","desc"), limit(25));
const snapshot = await getDocs(q);
-- version 22.2.0 -- this takes 9.492874 seconds:
const path = `clients/{clientId}/branches/{branchId}/orders`;
const ref = collection(db, path);
const q = query(ref, where("isPaid","==",true), where("order_date",">=","2025-05-17T21:00:00.000Z"), where("order_date","<=","2025-05-18T10:55:39.388Z"), orderBy("order_date","desc"), limit(9));
const snapshot = await getDocs(q);
-- version 22.2.0 -- while this takes 0.654975 seconds:
const path = `clients/{clientId}/branches/{branchId}/orders`;
const ref = collection(db, path);
const q = query(ref, where("isPaid","==",true), orderBy("order_date","desc"), limit(9));
const snapshot = await getDocs(q);
Project Files
Javascript
Click To Expand
package.json:
{
"@react-native-firebase/app": "^22.2.0",
"@react-native-firebase/auth": "^22.2.0",
"@react-native-firebase/firestore": "^22.2.0",
"@react-native-firebase/storage": "^22.2.0"
}firebase.json for react-native-firebase v6:
# 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:
buildscript {
ext {
buildToolsVersion = "35.0.0" // Latest build tools
minSdkVersion = 26
compileSdkVersion = 35
targetSdkVersion = 35
if (System.properties['os.arch'] == "aarch64") {
// For M1 Users we need to use the NDK 24 which added support for aarch64
ndkVersion = "24.0.8215888"
} else {
// Otherwise we default to the side-by-side NDK version from AGP.
ndkVersion = "27.1.12297006"
}
googlePlayServicesAuthVersion = "20.7.0" // Latest Google Play Services
supportLibVersion = "28.0.0" // Legacy; consider replacing with AndroidX equivalents
kotlinVersion = "2.0.21" // Latest stable Kotlin version
kotlin_version = "2.0.21" // Latest stable Kotlin version
androidXCore = "1.10.1" // Latest androidx.core
}
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath('com.android.tools.build:gradle:8.1.0') // Matches Gradle version
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.15' // Latest Google services plugin
classpath 'com.huawei.agconnect:agcp:1.9.1.300' // Latest Huawei AGCP
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://developer.huawei.com/repo/' }
}
// This is a fix for Android build error: 28/04/2025
configurations.all {
resolutionStrategy {
force 'org.bouncycastle:bcprov-jdk15to18:1.78.1'
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
}
}
}
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.10.1' // Force latest androidx core-ktx
}
}
apply plugin: "com.facebook.react.rootproject"android/app/build.gradle:
// N/Aandroid/settings.gradle:
// N/AMainApplication.java:
// N/AAndroidManifest.xml:
<!-- N/A -->Environment
Click To Expand
react-native info output:
OUTPUT GOES HERE
- 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:22.2.0
Firebasemodule(s) you're using that has the issue:@react-native-firebase/firestore
- Are you using
TypeScript?Y
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.
Activity
[-][🐛] Bug Report Title - 🔥 Slowness using complex queries[/-][+][🐛] 🔥 Slowness using complex queries[/+]github-actions commentedon Jun 16, 2025
Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions.
alkhatera commentedon Jun 19, 2025
Is there any updates or someone facing the same issue?
mikehardy commentedon Jul 1, 2025
@alkhatera sorry for the delay, we are a little behind in matching the upstream SDK releases here, and it is possible they have fixed something. It appears you reproduce this on both platforms - iOS and Android? Have you tried overriding the SDK versions to the latest (iOS: 11.15.0 / Android 33.16.0) using our temporary override mechanism: https://rnfirebase.io/#overriding-native-sdk-versions
If that doesn't work, it may be that the performance problem is in the SDKs, not in react-native-firebase, a quick way to check that is to try one of the quickstarts and make a reproducible example to see if the performance is still unexpectedly slow without the react-native-firebase layer in between your query and the native SDK
https://github.com/firebase/quickstart-ios/tree/main/firestore
https://github.com/firebase/quickstart-android/tree/master/firestore