Realm.io and asynchronous queries Realm.io and asynchronous queries multithreading multithreading

Realm.io and asynchronous queries


Christian from Realm here.You are right that queries are currently required to run on the thread they are used on, which potentially can have a negative effect on the UI thread performance. We are however acutely aware of this and are actively working on making it possible to move query results across threads.

That said queries in Realm are quite fast even for reasonable large amounts of data, and due to it only loading data you actually use can be very performant even when run on the UI thread.

I would encourage you to try it out with whatever data size you seem reasonable and test your performance (on a older device preferably :)). It is also possible to do tricks like adding indexes to keys, make the heavy query on a background thread, send keys to the UI thread and requery for them there. It is a bandaid but will work in some cases - Sadly not for lists though.


realm 0.84 support now async queries.

You can try it out by adding 'io.realm:realm-android:0.84.0-SNAPSHOT' to your build.gradle. There are a few new methods

  • findAllAsync
  • findAllSortedAsync
  • findFirstAsync

You have to add a addChangeListener(RealmChangeListener) to the RealmResult to get notified when the query completes.

Documentation: https://realm.io/docs/java/latest/#asynchronous-queries