Search code examples
objective-cioscore-datansfetchrequestfetching-strategy

General CoreData Performance


i have a more or less general question about using coredata the most efficient way.

i have attempted two different approaches of managing data that is shown in a view of my project.

Approach 1: when the view gets loaded i perform all coredata fetches and store the results in an array, the view then retrieves the displayed objects from the array. (ie: objectAtIndex:...)

Approach 2: the viewcontroller itself lets my data handling class perform fetches on the go, whenever a specific coredata object is needed it gets fetched.

on my current project this involes about 200-500 objects that need to be sorted and displayed in a tableview according to their attributes.

the fetch methods are the same wether i load all objects first or when i load them in batches (of correct attributes).

the difference is mainly in the cellForRow method where i have to decide if i want to pick the objects out of an array or directly from coredata.

both methods work just fine, i dont really see any performance differences just now, but i fear that with scaling of the project & more data one or the other way might be slower.

what do you think is the better way to do this?


Solution

  • With larger data sets there may be an advantage in terms of peak memory footprint to using NSFetchedResultsController controller that is, presumably optimized to fetch just the right amount of data from the persistent store based on the table size.

    With NSFetchedResultsController you have control over the fetch batch size which you can tune for performance based on the size and number of the managed objects being fetched, etc.