• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Keyword @defs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keyword @defs


  • Subject: Re: Keyword @defs
  • From: Greg Parker <email@hidden>
  • Date: Mon, 30 Nov 2009 13:47:35 -0800

On Nov 30, 2009, at 1:33 PM, Ben Haller wrote:
> On 30-Nov-09, at 4:06 PM, Bill Bumgarner wrote:
>> On Nov 30, 2009, at 12:50 PM, Dennis Munsie wrote:
>>
>>> Not that I'm advocating it, but you can also declare a field as @public to allow you to access it via the -> operator.  Of course, I could be missing some compiler magic going on behind the scene as well, and it may not actually be the same speed wise as @defs was.
>>
>> The compiler preserves the "non-fragile" part of "non-fragile ivars" when using the -> operator.
>>
>>> Not to mention that it's just plain nasty :)
>>
>> Yup, that it is.
>
>  This is interesting to me, since I am in fact using @public and -> with some ivars to allow faster use of one of my classes.  (Yes, I've confirmed that this is significant in Sampler; it is, in fact, quite a large percentage of the total time of my app, which has runtimes measured in days, so I do care :->).  I understand the concept of the fragile base class problem and so forth; I just didn't realize Apple had done something to fix it that might affect the performance of my app.  :->
>
>  What I want is essentially a struct with methods; I need super-fast access to ivars for clients of the class in some places in my code.  But I also want functionality provided by the class itself via methods, and I want a class hierarchy (so just using functions instead of methods gets ugly fast).  Is there a better solution than @public?  Or is there some reason I shouldn't worry about it -- is all the overhead just on the first pass through any given code path, with back-patching, for example?

@public is the best way to do this. (Well, @package may be slightly better, but it's probably only a theoretical improvement in launch time.)

The details are CPU-specific, but non-fragile ivar access is expected to use two or three loads where fragile ivar access used one load.

For ObjC code like this:
    x = self->YourIvar;

Fragile ivar access looks like this when compiled (in a fake assembly language I just made up):
    load r1 = self+offsetof(YourIvar)    // offsetof(YourIvar) is a compile-time constant

Non-fragile ivar access looks roughly like this:
    load r1 = &_OBJC_IVAR_$_YourClass.YourIvar
    load r2 = *r1
    load r3 = self+r2


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

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

References: 
 >Re: Keyword @defs (From: Oftenwrong Soong <email@hidden>)
 >Re: Keyword @defs (From: Bill Bumgarner <email@hidden>)
 >Re: Keyword @defs (From: Dennis Munsie <email@hidden>)
 >Re: Keyword @defs (From: Bill Bumgarner <email@hidden>)
 >Re: Keyword @defs (From: Ben Haller <email@hidden>)

  • Prev by Date: Re: iterating and removing objects from a collection
  • Next by Date: [MEET] December CocoaHeads Mac Developer Meetings
  • Previous by thread: Re: Keyword @defs
  • Next by thread: Re: Keyword @defs
  • Index(es):
    • Date
    • Thread