Different Ways to Fetch Data with Core DataPosted: June 24, 2012
For the life of me, I couldn’t find any decent information about optimizing Core Data fetches, specifically whether creating Fetch Request Templates improves performance. How best to use caches and indexes to improve performance. So I started some sample code to test these questions. Pretty simple app, but it gave me an opportunity to play with a data set from OpenDataPhilly. I picked the test scores of Pennsylvania high schools. Maybe, I’ll write something else using this dataset.
The source is up on github.
- Creating a Fetch Request Template is about 9 times faster writing out a NSFetchRequest.
- There’s got to be something I don’t understand about setting the cacheName value of NSFetchedResultsController, but it’s exactly the same speed.
- Creating an index improves performance as expected, approximately about an order of magnitude on this specific test.
- At first I thought that maybe creating a Fetch Template created an index which is why it improved performance. But it’s definitely more than that because when I created a Fetch Request Template on an indexed field, it improve performance even more.