Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS CoreData batch insert?

In my iPhone application, i need to insert ~2000 records into Core Data before the user can use any features of the application. I am loading the records into CoreData from a local JSON file. This process is taking a long time(2.5+ minutes), but only needs to happen once(or every ~10 application opens to get updated data).

Is there a batch insert for Core Data? How can i speed up this insert process?

If i can't speed it up using Core Data, what are the other recommended options?

like image 653
james Avatar asked Nov 10 '10 15:11

james


1 Answers

Check out the Efficiently Importing Data chapter from the Core Data Programming Guide.

I'm currently having the same problems as you, only I'm inserting 10000 objects and it takes around 30s, which is still slow for me. I'm doing a [managedObjectContext save] on every 1000 managed objects inserted into the context (in other words, my batch size is 1000). I've experimented with 30 different batch sizes (from 1 to 10000), and 1000 seems to be the optimum value in my case.

like image 58
Vladimir Mitrovic Avatar answered Sep 21 '22 12:09

Vladimir Mitrovic