Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data Performance: NSPredicate comparing objects

If my Author NSManagedObject model has a authorID attribute (determined by the server), will an NSFetchRequest perform better if the NSPredicate filters by authorID rather than the complete Author object? Let's say I'm fetching all Book NSManagedObjects by a certain author. Which predicateFormat is better?

[NSPredicate predicateWithFormat:@"author = %@", anAuthor]

or

[NSPredicate predicateWithFormat:@"author.authorID = %@", anAuthor.authorID]

What's the best way to profile this? I have Core Data testing working with OCUnit (SenTestingKit). Does iOS have something like Ruby's Benchmark module?

like image 336
ma11hew28 Avatar asked Dec 22 '11 23:12

ma11hew28


People also ask

What is Nspredicate in Swift?

A definition of logical conditions for constraining a search for a fetch or for in-memory filtering.

How do you start your NSFetchRequest?

You initialize an instance of NSFetchRequest as generic type: NSFetchRequest<Venue> . At a minimum, you must specify a NSEntityDescription for the fetch request. In this case, the entity is Venue . You initialize an instance of NSEntityDescription and use it to set the fetch request's entity property.


1 Answers

It might be worth running your app with an argument of -com.apple.CoreData.SQLDebug 1, as detailed here.

You could then see if Core Data was executing the same SQL in both circumstances (assuming you're using a SQLite store).

like image 91
paulbailey Avatar answered Sep 27 '22 23:09

paulbailey