If you have 200 thousand messages, first find the optimal preservation of the length of each message. It will be trial and error, I found 3000 optimal. run [save context] for every 3000, for example:
for(i=0; i<num of objects;i++) { // form the object to be saved in context if(i%3000==0){ // save the num of records , optimum value NSError *error; NSLog(@"saved rec nu %d",i); if (![context save:&error]) { NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); return NO; } [context processPendingChanges];// most important thing , if not objects will // keep adding in context and time would for insertion would drastically increase. } //for last set of the objects which are less than 3000 NSError *error; NSLog(@"saved rec nu %d",i); if (![context save:&error]) { NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); return NO; }
Let me know if anything ..
source share