Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
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