Better sorting using threads?
Better sorting using threads?
- Subject: Better sorting using threads?
- From: Graham Cox <email@hidden>
- Date: Thu, 11 Mar 2010 16:50:34 +1100
I've got a situation where sorting an array using sort descriptors is slow. The number of items being sorted is not enormous - about 2,000 - but there could be several sort descriptors and the main string one is using a localized and natural numeric comparison. I cache the results and take a lot of care only to resort when needed, but that doesn't help on the first run through which often takes in the order of 10-20 seconds. The interface that displays the results therefore beachballs for this time.
I'm considering using threads to help, where a thread is used to perform the sort itself, and until the sort has finished the UI can display a busy indicator (indeterminate circular progress indicator) next to the selected row in the table. This is in the master table of a master-detail interface where the detail displays the sorted items selected. While busy the detail view can be blank or show the previous arrangement.
So my question is, is threading a good solution? While NSMutableArray isn't marked as thread-safe, the array in question can be arranged to not be used outside of the sorting thread, and only substituted for the returned sorted items when complete. Or can array sorting not be done on a thread at all?
--Graham
_______________________________________________
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