Realm Xamarin.Forms list view performance


#1

I have a question about Realm and Xamarin.Forms. I’m investigating the efficiency and speed of Realm database on Xamarin.Forms platform. The results are pretty amazing. But I have an issue with Realm query results and list view binding.

To stress test the scenario I’ve made a database which contains 20.000 lets say products. The code is very simple, I have IEnumerable in my view model and I set it to Realm.All(); Everything works great, products are loaded, but on lower end Android devices particularly the scrolling is horrendously choppy. I see a little bit of choppiness also on iPhone 5s. All over the places, even in documentation they say that because of lazy loading nature of Realm you don’t need to implement pagination, but in case where you need UI support you can simply “read” a subset of IQueryable.

I couldn’t find any example where you would “read” the data in background thread and pass it back to UI thread. In our example it would make sense to load products for instance 200 at a time.

To summarize, there are 2 questions that I need to answer to be able to implement lazy loading

  1. How to read a chunk from IQueryable?
  2. How to read that chunk in a background thread, this is particularly interesting cause in Realm you are not allowed to pass objects between threads.

Any ideas?


#2

Have you measured if this choppiness is as a result of Realm loading data from disk or simply the drawing of the UI? I’d be very surprised if it’s the former. You can, for example create an unmanaged collection of 200 items and replace your IEnumerable with it and see how scrolling behaves on low-end devices.


#3

I’m banging my head over the wall how stupid I was not to try that :slight_smile: I tried and it was still choppy even with in-memory list. So, that was the issue of the device, not the Realm! And the fact that realm is THAT fast drives me crazy. @nirinchev thanks!