firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.54k stars 1.44k forks source link

Firestore Snapshot Listener executes too much work on main thread #7957

Open aryaxt opened 3 years ago

aryaxt commented 3 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

Snapshot listener executes large tasks on the main thread and makes the app extremely laggy. I was wondering if the code can be optimized to perform the work on a background thread

Steps to reproduce:

I don't see this issue on the Android client

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.

Relevant Code:

profiler.trace.zip

Screen Shot 2021-04-24 at 10 43 47 AM Screen Shot 2021-04-24 at 10 51 35 AM
morganchen12 commented 3 years ago

@aryaxt have you tried setting the callback queue to a background queue?

schmidt-sebastian commented 3 years ago

Can you also share the code of you listeners and approximate the number of documents in each snapshot? Raising the snapshot should not put a lot of work on the main queue, but accessing the document data inside of the snapshot may kick off expensive operations.

google-oss-bot commented 3 years ago

Hey @aryaxt. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

aryaxt commented 3 years ago

Thanks, I'll try the callback queue and report back

bguidolim commented 2 years ago

I'm setting the callback queue to a background queue, but doing this makes the listeners sometimes don't send any response. Tried using concurrent and serial queues, for now, I'm keeping the main queue to avoid this kind of issue.

I'm using now Firebase 9.4.1, but it's also happening on version 9.5.0. Xcode 14b6, iOS 16 beta.