Ran*_*idt 1 xcode objective-c ios automatic-ref-counting
我正在尝试将我的应用程序转换为ARC,但当我这样做时,它减慢了5倍:(
在我的图表视图中,我有这个代码块迭代所有点:
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());
Run Code Online (Sandbox Code Playgroud)
在ARC之前,此块在大约0.01秒内执行.然后,我使用ARC转换器,它愉快地将我的代码转换为ARC而没有任何抱怨.在此之后,我在相同的情况下运行相同的代码,得到.05秒的结果!它的速度减慢了5倍...所以我从快照恢复了我的旧项目,所以不再使用ARC,并且进行了10次测试,并且始终得到了0.01秒的结果.然后我将它转换回ARC并持续获得.05秒.XCode没有给我任何关于为什么会发生这种情况的线索......但我的其余代码也在减速.会发生什么事?
我有兴趣看到有问题的文件.在任何情况下,您都可以随时为所有内容启用ARC,但对于任何有问题的文件(在性能优化之后)将其关闭.这就是我们在Apple上构建一堆东西的方式.
我们通常为整个项目打开ARC,然后关闭特定文件.任何关闭它的文件都会得到:
#if __has_feature(objc_arc)
#error This file should not be built with ARC until blah-blah-blah is fixed.
#endif
Run Code Online (Sandbox Code Playgroud)