Shai UI
Shai UI

Reputation: 51976

IPhone: Why are Bulk Inserts in Core Data so slow?

So I'm making an iphone app that just has a thousand entries that I'm reading from an xml file into core data. But inserting these records takes like 10 seconds on the device. It's pretty ridiculous.

The schema is very simple, just one table. I.e., no relationships or anything.

To see what I mean, you can just go to:
1. File -> New Project -> Navigation Based Application (make sure 'use Core Data' is checked)
2. Now inside RootViewController.m go to the 'viewDidLoad' and at the very end of this method add:

   for (int n = 0; n < 1000; n++) [self insertNewObject];

And just run the app. Even in simulator it takes 5 seconds and on devices it's twice as slow. Any ideas??

Upvotes: 3

Views: 1015

Answers (1)

Shai UI
Shai UI

Reputation: 51976

Argh... I found the reason. I shouldn't save the context after each insert. My bad.

Upvotes: 2

Related Questions