Skip to content

[🐛] Slow write/read operations  #8891

@Feras532

Description

@Feras532

🔥 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

  1. Configure Firestore with persistence enabled and large cache size (see firebase.json below)
  2. Execute a query with multiple where clauses + orderBy + limit
  3. Measure time taken by getDocs()
  4. 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/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// Standard RN 0.80.2 configuration

android/app/build.gradle:

// Standard RN 0.80.2 configuration with Firebase dependencies

android/settings.gradle:

// N/A

MainApplication.java:

// Standard RN setup

AndroidManifest.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-firebase version you're using that has this issue:
    • 23.8.6
  • Firebase module(s) you're using that has the issue:
    • @react-native-firebase/firestore
  • Are you using TypeScript?
    • Yes & 5.x


Additional Questions

  1. Is this a known issue with persistence enabled on Android?
  2. Should cache_size_bytes: 524288000 (500MB) be reduced for better performance?
  3. Any recommended Firestore settings for Android performance optimization?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions