firebase / firebase/firebase-android-sdk

Seeing very high latency for local fetches from firestore on device db

Open
#6,673 9 comments 1 reaction 1 assignee Claimed by @cherylEnkidu View on GitHub
api: firestore needs-attention
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

### [READ] Step 1: Are you in the right place?

We are facing a very high latency upto 140ms to 200ms when trying to fetch firestore's local database. We understand that remote fetches can take a higher time but local fetches taking upto 150ms is not acceptable.

### [REQUIRED] Step 2: Describe your environment

* Android Studio version: Android Studio Meerkat | 2024.3.1 Canary 6
* Firebase Component: Firestore
* Component version: 33.7.0

### [REQUIRED] Step 3: Describe the problem
We are facing a very high latency upto 140ms to 200ms when trying to fetch firestore's local database. We understand that remote fetches can take a higher time but local fetches taking upto 150ms is not acceptable.

#### Steps to reproduce:

Any fetches from local database are latent, takes upto 150ms

#### Relevant Code:

private suspend fun executeDocumentTask(pageName: String?, fireStoreTask: Task, source: String, stylesList: String = EMPTY, tracer : Tracer? = null): DocumentSnapshot? = suspendCancellableCoroutine { coroutine ->
val startTimeMs = System.currentTimeMillis()
try {
tracer?.log("fireStoreManager.executeDocumentTask.addOnCompleteListener.start")
fireStoreTask.addOnCompleteListener {
tracer?.log("fireStoreManager.executeDocumentTask.inOnCompleteListener.result")
if (it.isSuccessful) {
application.trackInNewRelic(eventName = "firestore_fetch_success", attributes = mutableMapOf(
"reason" to "Exception - ${it.exception.toString()} || Reason - ${it.exception?.message.toString()}",
"source" to source,
"duration" to System.currentTimeMillis() - startTimeMs
))
if (it.result.exists() && "server".equals(source, true)) {
application.trackInNewRelic(eventName = "firestore_fetch_no_items", attributes = mutableMapOf(
"stylesNotFound" to stylesList,
"page" to (pageName ?: EMPTY)
))
}
if (coroutine.isActive) coroutine.resume(it.result)
} else {
application.trackInNewRelic(eventName = "firestore_fetch_failed", attributes = mutableMapOf(
"reason" to "Exception - ${it.exception.toString()} || Reason - ${it.exception?.message.toString()}",
"source" to source,
"duration" to System.currentTimeMillis() - startTimeMs
))
if (coroutine.isActive) coroutine.resume(null)
}
}
} catch (exception: Exception) {
application.trackInNewRelic(eventName = "firestore_fetch_failed", attributes = mutableMapOf(
"reason" to "Exception - ${exception.toString()} || Reason - ${exception.message.toString()}",
"source" to source,
"duration" to System.currentTimeMillis() - startTimeMs
))
if (coroutine.isActive) coroutine.resume(null)
}
}

val widgetPageDocumentFromCache = withContext(mainDispatcher) {
tracer?.log("getWidgetUrlFromPage.widgetPageDocumentFromCache.main.start")
val data = executeDocumentTask(pageName, documentRef.get(Source.CACHE), "cache", tracer =tracer)
tracer?.log("getWidgetUrlFromPage.widgetPageDocumentFromCache.main.end")
data
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.