1

After noticing that my problem is not a database specific problem, but an UI problem I'm creating this new question here. I have a SearchBar (source) that is used to filter a dataset from a realm database. This works so far well and fast. But when I want to display the result in a list it's pretty slow.

I've tried different approaches to display the elements. I thought the LazyVGrid could be a good solution for this use case since it doesn't create the view for each element but only when I scroll down and need to display them.

ScrollView { 
    LazyVGrid{
        ForEach(...)
    }
} 

But this approach was veeeery slow and sometimes my app crashed. So I switched to the classic approach with List{ ForEach(...){ } }.id(UUID()) that is my current solution. The performance is okay. ~2-3 second for 15.000 elements. Additionally my CPU and memory is increasing extremely for the 2-3 seconds. I'm not using any animations or other stuff. For testing I just used a single line text to represent each element.

I'm looking more for a solution like: Display the first n results immediately. And when I scroll down and really need the other results the view for each element should be created only then.

kirkyoyx
  • 313
  • 2
  • 12

0 Answers0