deadfa11.bsky.social
@deadfa11.bsky.social
Instead of var dailyAverages:[Date:Double] I think something like var monthlyAverages: [YearMonth: [Day: Double]] would allow a more granular approach that you could pass to the views and get better performance.
February 7, 2025 at 10:53 AM
The key issue is that dictionaries in Swift are value types. When you call dailyAverages.merge(), it creates an entirely new dictionary. From SwiftUI's perspective, the whole data source changed - even for dates that weren't part of this month's update.
February 7, 2025 at 10:47 AM
The killer here is that Date comparisons are expensive - they involve checking year, month, day, hour, minute, second, and timezone components. When you're doing this hundreds of times per update, it adds up fast!
February 7, 2025 at 10:45 AM
Can’t really answer about Swift Data but for Core Data you could do a batch of inserts using background context using something like 5-10k inserts at a time depending on the relationship between items. You could even try to do it in paralel.
January 30, 2025 at 9:06 PM