• 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: garbage collection and NSConnection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: garbage collection and NSConnection


  • Subject: Re: garbage collection and NSConnection
  • From: Marcel Weiher <email@hidden>
  • Date: Fri, 11 Jul 2008 23:25:16 -0700


On Jul 11, 2008, at 12:53 , Michael Ash wrote:


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:

[timings snipped]


I have no explanation as to why NSMutableString is so much slower at everything.

I do ;-)

They both end up creating an instance of NSCFString, so
this is puzzling. But there you are.

These sorts of tests can be tricky to get right: of the two, only the NSMutableString test is creating strings for you, your NSString test is just returning the same empty+constant string over and over (you can verify this by printing the object pointer). You can control for this, for example by using -initWithCString: with a buffer whose contents change slightly each time.


These are the numbers I get:

NSMutableString alloc+init(WithCString:) + release(/dealloc) : 1246 nanoseconds
NSMutableString alloc+init(WithCString:) + release(/dealloc) +retain/ release: 1365 nanoseconds
NSString alloc+init(WithCString:) + release(/dealloc) : 418 nanoseconds
NSString alloc+init(WithCString:) + release(/dealloc) +retain/ release: 527 nanoseconds


In both cases, the extra retain/release costs around 110ns, so allocation is 4x to 10x slower. (I have to admit the 4x surprises me a little bit, in my experience that value was higher).

The reason NSMutableString is slower is that it needs to allocate an extra buffer. NSString is pretty heavily optimized, it takes just as long to allocate as does an empty NSObject:

NSObject alloc+init+release(/dealloc):  417 ns

But of course the retain/release for NSObject is much more expensive:

NSObject alloc+init+release(/dealloc) + retain/release:  740 ns
NSObject alloc+init+release(/dealloc) + 2x retain/release:  1026 ns


So as I said: (a) object allocation slowest (b) out-of-band retain count slow (c) inline retain count much faster than either.


Regards,

Marcel

_______________________________________________

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


  • Follow-Ups:
    • Re: garbage collection and NSConnection
      • From: "Michael Ash" <email@hidden>
References: 
 >Re: garbage collection and NSConnection (From: "Joan Lluch (casa)" <email@hidden>)
 >Re: garbage collection and NSConnection (From: "Michael Ash" <email@hidden>)
 >Re: garbage collection and NSConnection (From: Marcel Weiher <email@hidden>)
 >Re: garbage collection and NSConnection (From: "Michael Ash" <email@hidden>)
 >Re: garbage collection and NSConnection (From: Marcel Weiher <email@hidden>)
 >Re: garbage collection and NSConnection (From: "Michael Ash" <email@hidden>)
 >Re: garbage collection and NSConnection (From: Marcel Weiher <email@hidden>)
 >Re: garbage collection and NSConnection (From: "Michael Ash" <email@hidden>)
 >Re: garbage collection and NSConnection (From: Marcel Weiher <email@hidden>)
 >Re: garbage collection and NSConnection (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Protocol-conforming object does not include retain?
  • Next by Date: Re: Trashing files and undo
  • Previous by thread: Re: garbage collection and NSConnection
  • Next by thread: Re: garbage collection and NSConnection
  • Index(es):
    • Date
    • Thread