I could not find an objective study regarding ARC performance impact in a real life project. The official doc says
The compiler efficiently eliminates many extraneous retain/release calls and much effort has been invested in speeding up the Objective-C runtime in general. In particular, the common “return a retain/autoreleased object” pattern is much faster and does not actually put the object into the autorelease pool, when the caller of the method is ARC code.
which has been relayed/deformed by tech-fanboys into "ARC is faster".
What I know for sure is what I measured. We recently migrated our iOS project to ARC and I did some performance measurement before/after on some CPU intensive area of our code (production code, compiled with the -Os
flag, of course).
I observed a 70% (yes 70%) performance regression. Using Instruments to track retain/release events, I realized that the compiler introduces a LOT of retain/release pairs in area where you would not do it (in pre ARC environment). Basically, any temporary becomes strong. That is, I believe, the source of the performance regression.
The original code, before the migration, was already quite optimized. There was barely any autorelease done. Hence, there was little room for improvement by switching to ARC.
Fortunately, Instruments was able to show me the most costly retain/released introduced by ARC and I was able to deactivate them using __unsafe_unretained. This slightly mitigates the performance regression.
Does anybody have any information on this or other technique to avoid the performance loss ? (apart from deactivating ARC)
Thanks.
EDIT: I'm not saying that ARC is bad because of the performance impact. The advantage of using ARC are largely superior than the performance regression (In our code, the regression did not have any visible effect, so I let it go). I consider ARC a very good technology. I will never go back to MRC. I'm asking this question more by curiosity.
I'm just slightly annoyed by the vast majority of blogs on the topic (like here and there) that more or less gives the impression that ARC code are going to be faster than MRC code (something I believed before I put my hands on it). And I really have the feeling this is not the case outside some micro benchmarks. At best you can hope to be on par with MRC, not faster. I made a few other simple tests involving objects manipulations (like counting word in a documents). Every time ARC was slower (thought not as bad as the 70% perf regression I was talking initially)
\begin{sarcasm}
In fact, the aforementioned doc did answer the question:
Is ARC slow?
It depends on what you’re measuring, but generally “no.” ...
which should obviously be understood as
\begin{parody}
Well ... hum ... we cannot say it's slower because this is a new cool techno and we would like you to adopt it. So we answer “no” with double quotes just to avoid a class action. And stop asking stupid questions.
\end{parody}
\end{sarcasm}