Hello, developers,
I'm experiencing UI lag in SwiftUI when updating Core Data or SwiftData entities in the background, noticeable during scrolling. This issue arises regardless of whether the updated entity is currently displayed. For instance, updating a "Song" entity with a new localURL
from a background download and saving background context affects an unrelated "Artists" list view.
Scenario: The lag is most evident when completing background downloads and updating entity properties, causing a hitch in scrolling interactions when using SwiftUI @FetchRequest or @Query for displaying data.
Observations:
- The issue occurs with both Core Data @FetchRequest and SwiftData @Query property wrappers.
- It affects unrelated views, suggesting a broader issue with SwiftUI's handling of data updates during user interactions.
Seeking Community Insights:
- Has anyone faced similar issues with SwiftUI and background data updates?
- Any strategies for reducing this lag/hitch?
- Insights into SwiftUI's data update and view re-rendering process in this context?
For a practical example, Apple's project on loading and displaying a large data feed demonstrates this issue. Try tapping the refresh button while scrolling to observe the lag.
Appreciate any advice or solutions!
Best Regards, [Personal Information Edited by Moderator]