flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[Firestore] App slow performance issue

Open expertdevs opened this issue 6 years ago • 7 comments

We are developing an flutter app (Pixz:- android & iOS) and everything works fine except the firestore queries. When we launch the app for the first time everything is smooth and run fine but after a while firestore queries jams the app. Simple save query takes 5 minutes to execute. See query below

---SAVE QUERY---

Firestore.instance.collection('Groups').document(groupID).setData({
  'id': groupID,
  'created_by': currentUser.uid,
  'title': titleText.text,
  'description': descriptionText.text,
  'isPrivate': true,
  'status': 1,
  'created_at': DateTime.now().millisecondsSinceEpoch,
  'updated_at': DateTime.now().millisecondsSinceEpoch,
  }).then((response) {
     print('success);
  }).catchError((error) {
     print('error);
  });

I upgraded to latest packages see below versions of Packages and also upgraded Flutter to latest stable version but no luck.

---VERSIONS---

firebase_auth: ^0.16.0 firebase_storage: ^3.1.5 cloud_firestore: ^0.13.5 firebase_messaging: ^6.0.13 firebase_remote_config: ^0.3.0+3 firebase_crashlytics: ^0.1.3+3 firebase_analytics: ^5.0.11 I read online about disabling the offline persistence but firestore package has deprecated the use.

Kindly suggest if someone has gone through similar problem.

Video URL (Save Query Issue)

expertdevs avatar May 30 '20 08:05 expertdevs

There's a number of reasons this may happen. Would you be able to debug it on the Native side? Does the slow-query actually happen when executing? Also are there any logs?

Ehesp avatar May 31 '20 08:05 Ehesp

Not, I only debugged flutter code , Yes when query execute the response time is very slow even It also take more time to getting the Document Snapshot and Query Snapshot. No logs for save data query other logs are available in video.

expertdevs avatar May 31 '20 23:05 expertdevs

Yes but could you debug it on native please?

Ehesp avatar Jun 01 '20 08:06 Ehesp

Hi @Ehesp I debugged the native code and found that the following method is where it's taking time. Kindly suggest if I need to dig more.

image
private void addDefaultListeners(final String description, Task<Void> task, final Result result) {
   task.addOnSuccessListener(
       new OnSuccessListener<Void>() {
         @Override
         public void onSuccess(Void ignored) {
           result.success(null);
         }
       });
   task.addOnFailureListener(
       new OnFailureListener() {
         @Override
         public void onFailure(@NonNull Exception e) {
           result.error("Error performing " + description, e.getMessage(), null);
         }
       });
 }

Also when tried to build with latest plugin I get to see following in console.

flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations.

The plugin cloud_firestore could not be built due to the issue above.

expertdevs avatar Jun 03 '20 05:06 expertdevs

Was problem in code. Firestore doesn't have any problem.

expertdevs avatar Jun 08 '20 09:06 expertdevs

@expertdevs I'm facing a similar problem, of very long firestore queries. Would you mind letting me know what the problem in your code was, so I can better track down this issue? Cheers.

Jethro87 avatar Jun 08 '20 15:06 Jethro87

Please create a new issue, with the exact query, sample document you're querying against and also let us know about the amount of documents in the DB and expected to be returned.

Ehesp avatar Jun 08 '20 16:06 Ehesp