Re: garbage collection and NSConnection
Re: garbage collection and NSConnection
- Subject: Re: garbage collection and NSConnection
- From: "Michael Ash" <email@hidden>
- Date: Fri, 11 Jul 2008 15:53:36 -0400
On Fri, Jul 11, 2008 at 2:17 PM, Marcel Weiher <email@hidden> wrote:
>
> On Jul 11, 2008, at 8:59 , Michael Ash wrote:
>
>>> The cost of a single refcounting op is negligible compared to the cost of
>>> object allocation, so these two are quite irrelevant.
>>
>> A quick test of this claim would appear to disprove it. On my Mac Pro,
>> an alloc/init/release cycle of NSObject costs about 290ns. Adding an
>> extra pair of retain/release costs about 480ns. I'm not sure how I can
>> reasonably measure the object allocation by itself, or the cost of
>> just retain or just release. But it seems clear that these refcounting
>> operations are quite significant in cost.
>
> This is the extra refcount table in action, and why inline reference counts
> can be such a performance win on objects that are frequently retained and
> released.
>
> Changing the object to an NSString (which has an internal reference count)
> yields the following results on my MacBook Pro:
>
> retain+release NSString: time per iteration: 67 nanoseconds
>
> Compare this with the times for NSObject, both retain/release and allocation
> / deallocation:
>
> retain+release NSObject 2->3 / 3->2 : time per iteration: 223 nanoseconds
> retain+release NSObject 1->2 / 2->1 : time per iteration: 276 nanoseconds
> alloc+dealloc NSObject: time per iteration: 415 nanoseconds
Seems that NSString and NSMutableString are just faster at everything.
In all cases, the cost of an extra retain/release for them is still
roughly 50% of the cost of an alloc/init/retain. Here are my raw
numbers, times in nanoseconds:
NSObject alloc/init/release 284.3
NSObject alloc/init/retain/release/release 495.7
Extra time taken: 74%
NSString alloc/init/release 40.2
NSString alloc/init/retain/release/release 73.4
Extra time taken: 45%
NSMutableString alloc/init/release 194.7
NSMutableString alloc/init/retain/release/release 300.7
Extra time taken: 54%
I have no explanation as to why NSMutableString is so much slower at
everything. They both end up creating an instance of NSCFString, so
this is puzzling. But there you are.
Mike
_______________________________________________
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