Re: mutableArrayValueForKey: truth or dare
Re: mutableArrayValueForKey: truth or dare
- Subject: Re: mutableArrayValueForKey: truth or dare
- From: Ken Thomases <email@hidden>
- Date: Thu, 17 Jun 2010 17:06:23 -0500
On Jun 17, 2010, at 12:10 PM, Mike Abdullah wrote:
> On 17 Jun 2010, at 17:47, Matt Neuburg wrote:
>
>> There is an assertion often encountered in people's blogs, answers to
>> questions on forums, etc., that the proxy object provided by
>> mutableArrayValueForKey: is inefficient
>
> This is wrong. The proxy only occurs a slight performance penalty over direct calling the accessor methods (in most cases 1 message send)
Well, you're right that it's only one additional message send. The point is, though, that having an impoverished interface to the property means that the proxy can only use inefficient means of updating the property, such that an NSArrayController (for example) has to do excessive work.
>> - in particular, that if you don't
>> also implement -countOfItems, -objectInItemsAtIndex:,
>> -insertObject:inItemsAtIndex:, and -removeObjectFromItemsAtIndex:,
>> then every change in the mutable array through the proxy replaces the whole
>> array. Is this true? Thx - m.
>
> This is true. How else could the proxy do its work? The docs are pretty helpful on how the proxy decides what to do.
And the docs also point out the inefficiencies. From <http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/KeyValueCoding/Concepts/SearchImplementation.html#//apple_ref/doc/uid/20000955-SW2>:
> Note: The repetitive set<Key>: messages implied by the description in step 2 are a potential performance problem. For better performance, implement methods that fulfill the requirements for Step 1 in your key-value coding-compliant class.
In other words, to Matt's question: it's not "in people's blogs, [...] on forums, etc."; it's from Apple's own documentation. It's not a rumor or superstition.
Regards,
Ken
_______________________________________________
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