Search code examples
performanceandroid-studiofirebasedelayinstant-run

Firebase android query performance issue


I have filtered query, which returns about 220 items with 8 fields each without child nodes. It's not tiny portion of data, but definately not the large one. On the pic below the following happens:

  1. Sec 25 - user click to load data, eventListener is created
  2. Sec 31 - data is completely loaded from Firebase DB
  3. 1 min 47 - onDataChange is called and data is presented

I've seen some top process in debugger: FirebaseDatabaseWorker. Looks like it does some loaded data processing. But 1 minute with 30%CPU?? Is it possible to optimize?

Thanks!

enter image description here

final DatabaseReference artRef = 
database.getReference("sales/"+store+"/articles");
Query query = artRef.orderByChild("familyId").equalTo(familyId);

        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
               for (DataSnapshot child : snapshot.getChildren()) {
                    Article article = child.getValue(Article.class);
                    article.id = Integer.parseInt(child.getKey());
                    articles.add(article);
                }

                adapter.notifyDataSetChanged();
            }

Solution

  • Disabling Instant Run in Android Studio made it from 1 minute to about 5 second to call onDataChange.