Core Data iPhone, how often should I call [managedObjectContext save: & error] when recording 50k records?

I will do import from XML to the main data. I have about 50 thousand objects to be added. My question is how often can I call [managedObjectContext save: & error]. For each added new object or all objects x or only at the end of the import 50,000?

Currently, I call it for each object and try to do it in just 10 thousand, and the import speed increases sharply, but after the first 30 thousand it fails:

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <NSCFSet: 0x13e760> was mutated while being enumerated.' 

Before I spend too much time trying to diagnose what is happening, I decided to check whether it was normal to cause savings on each entity?

Is the number of entities before the savings call limited by the amount of memory used by these entities?

+4
source share
1 answer

Do not save all entities that are wasteful and inefficient. The sweet spot depends on your data, but it is definitely more than every record and less than 50K :)

I would recommend starting with every 1k and tune from there when you move on to application development.

As for this error that you see, it has nothing to do with saving data. You delete or add objects to the mutable array while you iterate over it. This is not allowed for obvious reasons.

+4
source

Source: https://habr.com/ru/post/1307305/


All Articles