swiftData slow with large data

My database has over 100k entries and anytime I access it either via @Query or a custom Fetch request it freezes my apps UI for 10+ second.

My first question is anyone having performance issues with large data sets. If so how have you found to resolve it ?

My next question is does swiftUI load the entire database into memory with the @Query. As I feel it is seeing as my app becomes very slow and partially unresponsive.

lastly if I have 2 data models and 1 has a to many relationship to the other are both loaded into memory even though only @Query 1?

consider datamodels

model1 {
var name : String
@Relationship(deleteRule:.cascade) var lotsOfData :[LotsOfData]
 init....
}
LotsOfData{
var element1 : String
var element2 : String
var element3 : String
var element4 : String
var element4 : String
init ….
}

LotsOfData has 100K instances in the database.

if I @Query into model1 because it references LotsOfData through A relationship is all that data all called / loaded ?

thanks for the information

SwiftData as far as I know is a local SQLite database. If you call @Query it does load what you specified. I can not say if it loads ALL data at once, I think it does, tho I hope it uses some clever indexing under the hood. Custom indexing is currently not available in SwiftData.

If you want to work with the data, (generate graphs), I would async that. If you want to list the data, try paging and only load x entries.

For know SwiftData seems not build for big data batches.

swiftData slow with large data
 
 
Q