I have the same issues in my app.
I updating a lot of Models on a background thread with ModelActor (initialized with Task.detached)
But when call save on the ModelActor modelContext this lag happens. Mostly recognizeable while scrolling or switching screens throught navigation.
I think its because calling save will also notify to update the mainContext, which is needed to update the UI through @Query.
So it consumes a lot of main-thread time which makes the UI laggy..
I already implemented a solution to what until the scrollview stops, and calling save after that, but if the user starts scrolling again, the lag is recognizable again.I am experiencing the same issues in my app. I am updating several models on a background thread using ModelActor, which I initialized with Task.detached. However, when I call save on the ModelActor's model context, I notice a lag, particularly while scrolling or navigating between screens.
I believe this lag occurs because calling save also prompts an update to the main context, which is necessary for refreshing the UI for @Query. As a result, this process consumes a significant amount of time on the main thread, causing the UI to lag.
I've implemented a temporary solution by waiting until the scroll view stops before calling save. However, if the user begins scrolling again, the lag becomes noticeable once more.
I don't have any other solution besides avoiding @Query and using the background context only to fetch data..
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: