0

I am writing a SwiftUI app that uses a single Task(priority: .low) to do lots of HTTP requests as a low priority whose results are displayed in a Table.

There's several hundreds of MBs of data being aggregated to display totals, averages etc.

Thing is, I am only creating one Task, but this is causing my UI to hang. Why is this? I think I must have a fundamental misunderstanding around how tasks are created and how they relate to processes and threads.

I am using Mongo's Realm to store the data having become frustrated with Core Data. Does anyone have any experience of agonisingly slow apps using Realm?

There is far too much code to post, but all the HTTP requests are being made using URLSession's async methods. These data are being transformed and saved in my Realm. In any case, I certainly wouldn't expect this to cause the UI to hang! What might be going on?

I know it's tough to triage without code, but as I say there is a lot of it. I’m just after general guidance really, rather than a fix for a very specific issue.

serlingpa
  • 12,024
  • 24
  • 80
  • 130
  • It's impossible without code. You're stating Realm is slow in your use case but what aspect is slow? Is storing data slow? Reading data? Downloading data? Something else? Is this a sync'd or local app? We need a clear coding example of what is slow and if you feel it's Realm, narrow the code to the few lines you use to write/read/whatever the data and also include a summary of your realm models. Please take a moment and review [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Jay Mar 25 '22 at 17:55
  • You may want to make sure that you aren't writing to realm on the main queue. The debugger will help you there. Also, make sure you create your realm and write to realm in an autoreleasepool. Lastly, try to minimize your number of write transactions. You may find this helpful: https://stackoverflow.com/a/40130648/4081597 – Rob C Mar 27 '22 at 22:39

0 Answers0