I have some high-performance C++ that I need to interface with Objective-C, is there any performance penalty to just dumping this code into a .mm file that contains my Objective-C code vs. leaving this code in a separate .cpp file and extern-ing all the functions I need to call from the .mm file?
I have some high-performance C++ that I need to interface with Objective-C, is there
Share
There are a handful of issues here.
(1) if your C++ engine code is running in isolation — if the Objective-C is acting as the front-end that triggers the underlying engine — then there is no penalty at all. The C++ bits in ObjC++ compile just like regular C++.
(2) If you are calling into Objective-C from within the calculation engine, then you might have a performance issue on your hands. There is overhead in calling an Objective-C method — objc_msgSend() isn’t free (but close to it) — but generally not enough to be a problem in comparison to, say, a function call. However, in highly optimized C++, the compiler there may be optimizations that eliminate, even, function call overhead (it gets complex) to a large extent. An Objective-C method call cannot be inlined or optimized away.
(3) If you haven’t measured it and discovered a performance problem, don’t worry about it…