Re: NSTableView, NSArrayController and secondary sortings
Re: NSTableView, NSArrayController and secondary sortings
- Subject: Re: NSTableView, NSArrayController and secondary sortings
- From: Bill Garrison <email@hidden>
- Date: Sun, 9 Dec 2007 01:35:10 -0500
On Dec 9, 2007, at 12:34 AM, Adam R. Maxwell wrote:
There are some potentially serious performance problems if you
subclass NSSortDescriptor. If your sort key is a keypath and you
have a large array, you can blow out your autorelease pool on 10.4
because Foundation's valueForKeyPath: implementation is inefficient
(this is fixed in 10.5). Plus, you don't get the benefit of
NSArray's sort cache so it's abysmally slow.
[snip]
I put together a demo project for this at http://homepage.mac.com/amaxwell/.Public/kvcTest.zip
but haven't looked at it for a long time. YMMV.
I ran the demo project on an Intel MacBook w/10.5 and copied the
original sort-by-keypath tests to make another set of tests that
sorted by a simple key.
There's definitely a relative performance hit in subclassing
NSSortDescriptor for both cases.
2007-12-09 01:08:49.339 kvcTest[1337:10b] Sorting by key:
2007-12-09 01:08:58.371 kvcTest[1337:10b] BDSKTableSortDescriptor:
9.014829 seconds
2007-12-09 01:09:04.006 kvcTest[1337:10b] NSSortDescriptor:
5.628339 seconds
2007-12-09 01:09:16.325 kvcTest[1337:10b] FastTrivialSortDescriptor:
12.314142 seconds
2007-12-09 01:09:27.408 kvcTest[1337:10b] TrivialSortDescriptor:
11.079273 seconds
2007-12-09 01:09:27.891 kvcTest[1337:10b] Sorting by keypath:
2007-12-09 01:09:45.998 kvcTest[1337:10b] BDSKTableSortDescriptor:
18.102415 seconds
2007-12-09 01:09:52.134 kvcTest[1337:10b] NSSortDescriptor:
6.133027 seconds
2007-12-09 01:10:29.562 kvcTest[1337:10b]
FastTrivialSortDescriptor: 37.424652 seconds
2007-12-09 01:11:05.396 kvcTest[1337:10b] TrivialSortDescriptor:
35.830598 seconds
The demo tests sorting an array of 200,000 objects:
@interface ValueObject : NSObject
{
NSString *title; // String containing a randomized value.
NSDictionary *dictionary; // contains above title string under key
'title'
}
@end
----
Maybe you'll never have 200,000 objects managed by your array
controller, so the performance difference may not be an issue.
On the other hand, maybe NSArrayController would be the better
location for implementing a secondary sorting.
- Bill
_______________________________________________
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