I already asked a similar question but still can’t get it to work. I have a core data database with 30k+ records. I am trying to fetch it into a tableview. I watched the WWDC presentation on core data and whatever the presenter suggested it didn’t work for me. I deleted most of the fields from that table and only left like 4 which contains nsstring and date. I used setFetchBatchSize with different numbers and still when using instruments the fetch controller was fetching all 30k records. I watched it over and still not sure what i am doing from to lower the fetch. I used a separate thread and showed svprogreshud but that made it even slower i guess because the thread is not running right away.
Also The data is divided 12 sections and i have a field in core database for it with one character to set up sections.
I also set -com.apple.CoreData.SQLDebug 1 and when running on the device it showed 3sec loading that fetch request with all the records but showed
CoreData: sql: pragma cache_size=200
CoreData: annotation: total fetch execution time: 3.1087s for 36684 rows.
Here is some of the code
-(void)useDocument{
if (self.peopleDatabase.documentState == UIDocumentStateClosed){
[self.peopleDatabase openWithCompletionHandler:^(BOOL success){
[self setupFetchResultsController];
}];
} else if (self.peopleDatabase.documentState == UIDocumentStateNormal){
[self setupFetchResultsController];
}
}
-(void)setupFetchResultsController
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"people"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"pplicon" ascending:YES]];
[NSFetchedResultsController deleteCacheWithName:nil];
self.fetchedResultsController = nil;
[request setFetchBatchSize:50];
//[request setFetchLimit:100];
self.fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:request managedObjectContext:self.peopleDatabase.managedObjectContext sectionNameKeyPath:@"pplicon" cacheName:@"peopleCache"];
}
Thank you in advance!
UPDATE
Jody thank you again for answering.
I went to the core data setup to the table and pplicon indexed is checked. Do i need to check anything else. I followed the directions for the wwdc video and ran instruments in core data fetches it shows NSManagedObjectContext executefetch .. Fetch Count 36684 and then another one with Fetch Count 12 Also in sampler the most time spent in peopleviewcontroller setupfetchResultsContoroller 363.75ms and UIAplication Run 287.6ms. In activity Monitor the app takes up 91mb real memory. Is there anyway to improve this time? What else can i check and see where the hang up is?
As far as the sections. I have a character in the database pplicon which used to show for section and the data is sort by it.
Data Model for now has one Entity with 5 Attribues as string and 1 Attribute as Date
I think I have commented on a very similar question in the past. You absolutely must run Instruments and see what it says. It will tell you exactly where it is spending its time.
You are using sections, which can be expensive. Is your section attribute “pplicon” setup in the database as an Index? If not, you will most definitely have to scan all items in the database. The only chance you have of not scanning all records is to make it an index. The internals may be able to just use an index table to get the unique index values. However, it still has to return section objects.
Again, you must turn on instruments while testing so you can see exactly where you are spending your time.