Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
- Subject: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
- From: John McCall <email@hidden>
- Date: Thu, 21 May 2015 16:59:53 -0700
> On May 21, 2015, at 4:44 PM, Graham Cox <email@hidden> wrote:
>> On 22 May 2015, at 3:02 am, Jens Alfke <email@hidden> wrote:
>>
>>> Now that I have a path forward and understand why things are what they are, this brings up the wonderful speed issue of "how much slower is property access vs ivar access”.
>>
>> Yeah, I think we’ve had some vigorous debates about this topic in the past.
>
>
> Anecdotally, with some coarse measurements to confirm it, I changed a bunch of code in -initWithCoder: to set ivars directly instead of using the property accessors (or -set<Foo>:). For a very large object graph - I’m talking hundreds of thousands of objects - the speed-up was dramatic. Dearchiving that large file went from 11 MINUTES to about 2 seconds.
>
> Because -initWithCoder: is an init method, setting ivars directly is par for the course, and at that time there can’t be any KVO observations depending on the property accessors, so it’s fine. However, if you have autosynthesized all your properties, to be completely safe and future-proof, you probably shouldn’t be doing this, even though right now the ivar names are predictable. That means that performance could be an issue with autosynthesized properties.
The synthesized ivar name algorithm is not an implementation detail. It is fully specified as follows: the compiler prepends a ‘_’ to the property name. Do not worry about future releases of the language changing the ivar name.
John.
_______________________________________________
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