https://kotlinlang.org logo
Title
p

Priya Sindkar

03/31/2023, 6:00 AM
Hello everyone, I am currently working on an android app which uses realm database. We are using architecture which abstracts RealmObjects obtained from Realm queries and converting them to local instances (standalone model replicating RealmObjects data). My problem is- When we have just 550 RealmResults (with several nested objects and nested RealmResults inside each item) and we try to use map() function to transform the RealmObjects to the local models there is ~3s delay. This is a serious performance issue we are facing with only 550 rows of the parent RealmResults list. Using copyFromRealm() and directly using this List<RealmObjects> reduces the delay to ~1s but as the rows in db will increase, so will this delay. Can anyone please suggest a better way to reduce this delay and keep using the local model instances?
s

s3rius

03/31/2023, 9:07 AM
I can imagine that it's simply a lot of data since you mentioned nested data structures. In this case, maybe you can change your data structure (or the way you fetch data from Realm) to reduce the amount of data that is loaded at once, and fetch the detailed item data when you actually need it. Or perhaps there is a paging functionality for Realm that you could use. The sledgehammer method would be to parallelize the
map
operation to run on several threads. That should lower the transformation time but doesn't really solve the underlying issue.
p

Priya Sindkar

04/01/2023, 5:48 AM
Ok thank you.. I can try to parallelize the map() operation.. changing the data structure may not be possible.. pagination is also not an option as some metrics are derived from all the rows fetched