Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a performance penalty associated with calling a function within a @try block?

Tags:

objective-c

Would this cause a performance penalty, compared to calling blabla without the try block?

-(void)bla{
    @try{
        [self blabla];
    }
    @catch (NSException *e) {
        // Do nothing
    }
}
like image 384
Pétur Ingi Egilsson Avatar asked Feb 25 '14 20:02

Pétur Ingi Egilsson


2 Answers

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

like image 56
Bryan Chen Avatar answered Dec 07 '22 06:12

Bryan Chen


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.

like image 32
CouchDeveloper Avatar answered Dec 07 '22 07:12

CouchDeveloper