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 9089043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:02:57+00:00 2026-06-16T22:02:57+00:00

I have two models, with a many-to-many relationship between them. The model A starts

  • 0

I have two models, with a many-to-many relationship between them. The model A
starts in an empty state, while the model B has about 220k records (with a quite
big index, but this shouldn’t affect, since this model is never updated).

The to-many from A->B is as follows:

  • optional => false
  • transient => false
  • indexed => true
  • ordered => true
  • minCount => 0
  • maxCount => NSIntegerMax
  • deleteRule => NSCascadeDeleteRule

The to-many from B->A is as follows:

  • optional => true
  • transient => false
  • indexed => false
  • ordered => false
  • minCount => 0
  • maxCount => NSIntegerMax
  • deleteRule => NSNullifyDeleteRule

And of course, each relationship is set as inverse of the other. The problem I’m
facing is the following: prior to create a new entity A, the app performs a
fetch request which gets about 2k records of the entity B. Then, the app sets
these records to the entity A about to be created, and then saves the context.
The problem is setting the nsorderedset of 2k records to the entity A instance
is taking 4 seconds more or less in an iPhone 4S with iOS 6.0.1, and saving the
context is taking another 4 seconds more or less, in the same device. That makes
8 seconds to create a new instance of model A.

I’ve tried enabling/disabling the indexed association property in model A, but
that didn’t make such a difference. It’s that heavy the task I’m trying to
achieve?

Making some tests, I’ve observed that most of the time lost setting the
nsorderedset to the entity A instance is because of the inverse relationship. I
made a quick test changing the many-to-many relationship to a to-many without
inverse relationship in the target model, and then the insert time went down to
half the time. Of course this breaks the many-to-many relationship. It was just
a quick test.

Am I missing something here? Since the app is saving the context just one time,
and not one time per each record B, it shouldn’t take that long to save 2k
records, but I’m new to iPhone development, and maybe this task I’m performing
is too much for this kind of device.

Any hints would be greatly appreaciated. Thanks!

  • 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-16T22:02:58+00:00Added an answer on June 16, 2026 at 10:02 pm

    Ferdev,

    Thank you for a well written question. It is clear you have thought carefully about your problem before asking for help. This helps everyone.

    Core Data does not appear to use block operations when it saves. Hence, you are going to have performance issues there. The relationship setting though should be faster than you’re seeing.(BTW, most of the performance issues are driven by the speed of flash memory. It is slow on iOS devices. Hence, prefetching to keep your MOC hot with your data is important. Bulk fetching is important.)

    I make several observations:

    Why is the A->B to-many relationship both indexed and ordered? The ordering will slow down your inserts. Does it also make sense to index a relationship?

    Are you using the bulk relationship setters (-add<Key>:)?

    Are you fetching all 2000 of your entity B records before you set them to the entity A instance?

    Even though this doesn’t affect your insert performance, why does the delete rule from A->B cascade? You write above entity B doesn’t change.

    Andrew

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

Sidebar

Related Questions

I have two models, Project and Category, which have a many-to-many relationship between them.
I have two models Property and Amenity the relationship between them is many to
I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
Say I have two models, Book and Author with a has_and_belongs_to_many relationship between them.
I have a one to many relationship between two objects, lets call them Gallery
I have a many-to-many relationship between two models, Lists and Users. When a user
I have a table joining two models in a has many through relationship. Users
I have two scaffold-generated Models, student and class . They have a many-to-many relationship
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
i have two models: class Category has many :jobs end class Job belongs_to :category

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.