This is a follow-up post to an earlier post I made regarding the performance of updating a relationship property in thousands of managed objects. After some profiling with Instruments, it became clear that the performance bottle neck was actually in NSArrayController. Since that ArrayController had a binding with an NSTableView I started to wonder if the performance hit was actually caused by all the UI updating that needed to happen. Sure enough it was. If I unbind the ArrayController before I update all the managed objects, then rebind the ArrayController afterwards, then I get great performance and the CoreData state is correct. Is unbinding the ArrayController the "correct" or a "valid" thing to do? It seems like a bit of a hack...

        More details of the setup for those interested:

I have two NSTableViews in a Window. Call them Playlists and Songs. Each has an NSArrayController with standard bindings. The playlistsController is bound to the managed object context of the application and shows entities of type "Playlist". The songsControllers' contentSet is bound to the selected playlists songs. Click a different playlist and the songs table view updates. I think this is the standard master/detail view setup. Works fine. However, if I load a playlist that contains a few thousand songs then drag those songs from the songs table view over to a playlist the operation will take several minutes. Profiling showed that the most amount of time is spent in the songsController. My guess is that every time I change the songs managed object (by doing something like:

        theSong.playlist = destinationList

Then everytime this happens the songs array controller gets notified, it has to find the song in question, remove it from its list of arrangedObjects, notify the NSTableView that the content set has been changed, and then the NSTableView needs to find the row and remove it. This, apparently, is not a fast operation. So by unbinding the songsController from the table view, doing all the updates, then rebinding the controller back, I get the performance, back presumably because the table view can then just do one big update when it's rebinded (rebounded?).

So I'm just wondering if there's a better way to do this. Seems like I need some ability to tell the array controller that I'm about to update a few thousand objects on it and to suspend notifications to the tableView until I'm done or something like that.

Thoughts?

Sincerely,
Kenny
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to