• 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: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!


  • Subject: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 23 Sep 2009 20:57:51 -0700


On Sep 23, 2009, at 6:10 PM, Graham Cox wrote:

I thought that NSEnumerator was implemented in terms of fast enumeration "underneath" - the docs seem to imply that, as does the existence of __NSFastEnumerationEnumerator private class. It may be still slower than directly using the fast enumeration syntax, but isn't there some gain to be had?

Maybe some, but not much. I did a lot of profiling and experimenting with enumeration, some of which I think ended up in the NSFastEnumeration design, and I found that the message-send-per-object was the biggest part of the overhead, and the creation (and eventual cleanup) of the autoreleased NSEnumerator object was significant too. There's no way around these when using NSEnumerator directly, or even iterating arrays by index.


That said, the overhead is often not major compared with the cost of what's going on inside the body of your loop, and how often the loop runs. So I wouldn't worry unless you have done profiling that shows some of these loops as hot-spots.

—Jens_______________________________________________

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: 
 >[__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast! (From: Matt Gough <email@hidden>)
 >Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast! (From: Jens Alfke <email@hidden>)
 >Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast! (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Controlling Spaces and retrieving information about the current Space?
  • Next by Date: Re: How to do what Finder does programmatically
  • Previous by thread: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Next by thread: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Index(es):
    • Date
    • Thread