• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Efficient Updating of Thousands of NSManagedObject Relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Efficient Updating of Thousands of NSManagedObject Relationships


  • Subject: Efficient Updating of Thousands of NSManagedObject Relationships
  • From: Kenny Carruthers <email@hidden>
  • Date: Mon, 28 Jul 2008 13:22:43 -0700

Given an array of NSManagedObjects, is there an efficient way to batch update a relationship on each object? Iterating through the array and setting the relationship using any of the available methods is incredibly slow when doing this on thousands of objects.

	As an example, assume the following:

You have an NSArray of NSManagedObjects that each represent a song. They have a to-one relationship to a playlist entity, which in turn has a to-many relationship to a song. I want to "move" all the songs from one playlist to a different playlist. The following pseudo code is ridiculously slow for large numbers of songs.

NSManagedObject *destinationList = .....;
NSArray *songURIs = ....; (Array of URI/URLs for each managed song)

for (song in songs)
 NSManagedObject *song = ... (Fetch some from proper context)
 song.playlist = destinationList
end

From a small amount of profiling I can tell that the line "song.playlist = destinationList" is killing performance, so I'm guessing a bunch of validation or something is being done when updating the songs relationship. Is there a way to batch make this change to improve performance? (Or maybe there's an entirely different way I'm supposed to do this?)

Not that this is using an XML store, but I briefly tried with a SQLite store and didn't see much difference.

For what it's worth, the end result once the operation finishes is correct, in that all the songs are in the proper playlist, it just takes the machine ages to process the changes (like 0.5 to 1 second per object).

Thank You.

Kenny Carruthers


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Efficient Updating of Thousands of NSManagedObject Relationships
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: Drawing Graphs in Cocoa
  • Next by Date: Predicate Binding Format/case sensitive question ...
  • Previous by thread: Re: Drawing Graphs in Cocoa
  • Next by thread: Re: Efficient Updating of Thousands of NSManagedObject Relationships
  • Index(es):
    • Date
    • Thread