[__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
[__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
- Subject: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
- From: Matt Gough <email@hidden>
- Date: Wed, 23 Sep 2009 22:27:31 +0100
I have an NSEnumerator iterating over an NSMutableArray like so:
NSEnumerator *iter = [myMutableArray objectEnumerator];
while (syncInfo = [iter nextObject]) {
... Do some stuff
}
Upon instrumenting it, I noticed that nextObject was taking over 60%
of the time, and most of that time is futzing around seemingly calling
__CFArrayCopyDescription.
1438 -[MyObj cleanSyncList]
1319 -
[__NSFastEnumerationEnumerator nextObject]
1319
__NSFastEnumerationMutationHandler
1239 CFCopyDescription
1239 __CFArrayCopyDescription
1183 CFCopyDescription
1180
__CFBasicHashCopyDescription
1171
CFBasicHashCopyDescription
1162 CFBasicHashApply
1160
__CFBasicHashCopyDescription_block_invoke_1
1070
CFCopyDescription
851 -[NSObject
(NSObject) _copyDescription]
849 -[NSDate
description]
847 -
[NSDate descriptionWithLocale:]
435
CFDateFormatterSetFormat
427
__ResetUDateFormat
382
udat_open
351
icu::DateFormat::create(icu::DateFormat::EStyle,
icu::DateFormat::EStyle, icu::Locale const&)
349 icu::SimpleDateFormat::SimpleDateFormat(icu::DateFormat::EStyle,
icu::DateFormat::EStyle, icu::Locale const&, UErrorCode&)
347 icu::SimpleDateFormat::construct(icu::DateFormat::EStyle,
icu::DateFormat::EStyle, icu::Locale const&, UErrorCode&)
231
icu::SimpleDateFormat::initializeSymbols(icu::Locale const&,
icu::Calendar*, UErrorCode&)
231
icu::DateFormatSymbols::DateFormatSymbols(icu::Locale const&, char
const*, UErrorCode&)
230
icu::DateFormatSymbols::initializeData(icu::Locale const&, char
const*, UErrorCode&, signed char)
166
icu::GregorianCalendar::GregorianCalendar(icu::GregorianCalendar
const&)
Why!!
I presume that if I swapped this for a simple :
for (i = 0; i < [myMutableArray count]; ++i) {
syncInfo =[myMutableArray objectAtIndex:i];
.....etc etc
}
it would speed up enormously.
I just don't understand why a supposedly fast enumerator is doing such
a seemingly stupid thing as to get the description of the array each
time around.
Any clues?
Matt Gough
BTW - OS X 10.6.1
_______________________________________________
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