Re: NSMutableArray sorting
Re: NSMutableArray sorting
- Subject: Re: NSMutableArray sorting
- From: Ben Trumbull <email@hidden>
- Date: Mon, 22 Dec 2008 13:55:52 -0800
On Dec 22, 2008, at 8:13 AM, Adam R. Maxwell wrote:
On Dec 22, 2008, at 1:09 AM, Ben Trumbull wrote:
I've never seen it documented though perceived performance would
indicate this is indeed the case
Generally, implementation details about caching behaviors falls
isn't something that gets formally documented. It's not part of
the API contract, and can change some from release to release.
That said, Robert is right that NSSortDescriptor does significant
caching throughout the sorting. It assumes the results of
valueForKey are stable for the duration of the sorting operation.
If your custom comparison function is based on valueForKey,
NSSortDescriptor will do a much better job than -
sortedArrayUsingFunction. That said, NSSortDescriptor is really
only happy with keys and keypaths, and overriding its comparison
method will disable the caching.
In fact, I discovered this while trying to figure out why an
NSSortDescriptor subclass with a comparison override gave such
abysmal performance; it was calling valueForKeyPath: so many times
while sorting a few thousand objects that it filled the autorelease
pool and crashed the app. A lot of time looking at Shark traces for
Apple's sorting led me to write my own NSArray sort method that
gives similar performance, even when using NSSortDescriptor
subclasses. Unfortunately, Apple wasn't interested in that.
I would recommend you encourage other people who want to see that
change file enhancement requests at bugreport.apple.com
- Ben
_______________________________________________
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