Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:17:00+00:00 2026-06-13T09:17:00+00:00

I am setting up Core Data in an application using UIManagedDocument . I am

  • 0

I am setting up Core Data in an application using UIManagedDocument. I am then adding around 1000 NSManagedObject(s) to the data base in a loop. I am initially processing the data for the objects in a background thread using:

dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(backgroundQueue, ^{
    // PROCESS OBJECTS HERE
    ...
    ...

Before adding them to Core Data from the background thread:

NSManagedObjectContext *moc = [[self managedDocument] managedObjectContext];
[moc performBlock:^{
    // ADD TO CORE DATA
    ...
    ...

using:

// CREATE
Fruit *fruit = [NSEntityDescription insertNewObjectForEntityForName:@"Fruit" inManagedObjectContext:context];
// POPULATE
[fruit setName:name];
[fruit setAge:age];
[fruit setType:type];
...

My question is:

Doing the above for 1000+ objects is currently taking about 2.2secs, I am not doing any saves on Core Data until all the objects have been inserted so its all done in memory with no I/O overhead. As you can see above all my processing is done on the background thread, but when I come to insert the new object into Core Data I have to use performBlock: to make sure the insert is done back on the main thread where the UIManagedDocument was originally created.

What I would like to know is, is there a way to speed up inserting the objects, maybe by “batching” a number of NSManagedObjects together and add them in one hit, or is that just going to take the same amount of time as what I am doing now (its still adding 1000+ objects).

I did read something about creating a new context and then merging that with the NSManagedDocument context, but I am not sure if thats appropriate or how to do it if it is. Any help / information would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:17:01+00:00Added an answer on June 13, 2026 at 9:17 am

    1) Set the undo manager on your context to nil:

    [moc setUndoManager:nil]
    

    The undo information is not required if you’re never going to undo during the save.

    2) You’re already batching by adding a number of objects with a single save.

    3) Experiment with smaller batch sizes. One large save at the end can be problematic, although 1000 should be fine.

    4) You’ll also want to experiment with releasing the objects you’ve created if you change the batch size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application using Core Data which heavily depends on setting attributes
I'm using a NSPersistantDocument backed by Core Data in my application. Each document has
I'm developing a data-driven application using Core Data. I display the tables from the
Using core data on a on an application that has tabbed views. The second
I'm having issues setting the delegate of a Core Data object to a certain
All right, after having worked through Cocoa Dev Central's Build a Core Data Application
I am working on an application that incorporates iCloud syncing of its Core Data
I've got 2 applications using Core Data with a sqlite persistent store. I've got
Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
Setting the scene: My asp.net web application carries a version number which is incremented

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.