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.

3
  • Could you provide minimal reproducible example (say with Text subviews)? Commented Jan 4, 2021 at 9:50
  • I'm not sure what example you need. Actually it's just a list with ~15.000 Text elements. Commented Jan 4, 2021 at 11:19
  • Not reproducible with your LazyVGrid code snapshot and 15000 Text items in adaptive column. Xcode 12.1 / iOS 14.1 Commented Jan 4, 2021 at 13:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.