Today, I was testing my app with large data (not quite large actually, 2000 records in total), and noticed that toObject()
method is performing slow.
Basically, I get a list of records from firestore, process it to show in UI, and pass it to RecyclerView
. To verify, I removed all of my processing logic and kept only toObject()
. It is the bottleneck, taking approximately 9 seconds in total.
Here is my code:
public ArrayList<MyModel> doProcessing(Context context, QuerySnapshot snapshots) {
ArrayList<MyModel> listToReturn = new ArrayList<>();
for (DocumentSnapshot snap : snapshots.getDocuments()) {
MyModel myModel = snap.toObject(MyModel.class);
...
... // my processing logic
... // check the data and set other fields of myModel based on it
...
listToReturn.add(myModel);
}
return listToReturn;
}
Here is a screenshot of MyModel schema(?!). It is not that heavy.
How to work around this? Anybody experiencing the same issue?