Would this cause a performance penalty, compared to calling blabla
without the try block?
-(void)bla{
@try{
[self blabla];
}
@catch (NSException *e) {
// Do nothing
}
}
Would this cause a performance penalty, compared to calling blabla
without the try block?
-(void)bla{
@try{
[self blabla];
}
@catch (NSException *e) {
// Do nothing
}
}
from doc
Zero-Cost @try Blocks
64-bit processes that enter a zero-cost @try block incur no performance penalty. This is unlike the mechanism for 32-bit processes, which calls setjmp() and performs additional “bookkeeping”. However, throwing an exception is much more expensive in 64-bit executables. For best performance in 64-bit, you should throw exceptions only when absolutely necessary.
so no overhead for 64-bit processes
You might be interested in this blog here: LLVM PROJECT BLOG
That is, on Intel and since Okt. 2013, on ARM too, C++ exceptions are now "zero-cost".
The Objective-C exceptions are realized in terms of this implementation.
However, the need for an unwinder will disable a few optimization opportunities, so that code which requires to handle exceptions might be less optimal optimized that when no exceptions have to be handled.
On some platforms, @try/@catch is "zero cost". There is no additional code executed for a try block as long as no exception is thrown. There is extra overhead in the form of exception unwinding data, but that also occupies no real memory until an exception is thrown. These platforms include 64-bit OS X and 64-bit iOS.
On some platforms, merely entering @try incurs some CPU overhead to save registers. These platforms include 32-bit OS X and 32-bit iOS.