I am trying to convert my app to ARC but when I do it slows down by a factor of 5 🙁
In my graph view I have this block of code that iterates over all points:
NSLog(@"%f", CACurrentMediaTime());
for (NSUInteger xIndex = firstXValueOnScreen; xIndex <= lastXValueOnScreen; xIndex++)
{
float value = 5; //This used to call a function to get the value but I took out the function call to better demonstrate that this seems to be just a general slowdown...
if (extremesUninitialized)
{
yMax = value;
yMin = value;
extremesUninitialized = NO;
}
else
{
yMax = MAX(yMax, v,alue);
yMin = MIN(yMin, value);
}
}
NSLog(@"%f", CACurrentMediaTime());
Before ARC this block executes in about .01 seconds. Then, I use the ARC converter, which happily converts my code to ARC without any complaints. After this I run the same code under the same circumstances and get a result of .05 seconds! It’s slowed down by a multiple of 5… So I restored my old project from a snapshot, so no more ARC, and did the test like 10 times and consistently got a result of .01 seconds. Then I converted it back to ARC and consistently got .05 seconds. XCode isn’t giving me any clues here as to why this is happening… But the rest of my code is slowing too. What could be going on?
There can only be a handful of options – it must be one of these:
1) your old code uses the optimizer at say -Os and the new code does not (so, you should be testing with “Release”) not “Debug” configuration.
2) the value of (lastXValueOnScreen – firstXValueOnScreen), ie the range you are doing, is different (for who knows what reason, you would have to do some searching)
3) There is some background task – some thread – that is running amuck when you enabled ARC but its not there normally.
So some ideas on how to find this:
1) double check the Scheme configure setting in both, make sure its Release (not sure if ARC runs slower in Debug or not, but Debug for sure slower than Release).
2) Add these two values to your log statement above the for loop.
3) Move this whole chunk of code to your appDelegateLaunched method, before you do anything else , or even better put it in an “+(void)initialize” method in appDelegate (so it runs before any of your other code). Hard code large balues for your two variables.
Every single doc I’ve read on ARC says its faster; every Apple engineer says its faster; my experience is its faster.