Objective-C Performance in the Programming Language Continuum

objective cprogramming-languages

There seems to be a lot of discussion of the various speed merits to C or C++ as compared to say Java or Python, but I rarely see Objective-C mentioned. Roughly where does it fall in terms of language performance?

Best Answer

Unlike C++, Objective-C is designed as a clean superset of C. The few Objective-C compiler I've used are better known as C compilers, but also handle Objective-C.

So, it's safe to assume that in the code generation level, C and Objective-C are equivalent.

The first difference appears in the OOP ABI, also called "late method binding". Just like in C++, Objective-C relies in compiler-generated function pointer tables that are traversed at runtime.

Unlike C++, however, the binding method is more 'dynamic', and promotes the use of the id superclass everywhere, making it slightly slower than C++ in theory. In practice, this difference is way below measurable.

Finally, the most important performance issue is the quality of the libraries used. Since Objective-C is only really popular in the Apple systems, it's reasonable to assume you're using it with Cocoa; which is a fine set of high-level libraries. In most cases, you can leave the heavy lifting to them, so your code either don't have to be so fast, or if you do heavy crunching, then it's likely to be a mostly-static code base, roughly similar to plain C.

TL;DR: it's right there with C and C++ languages where it matters most. If you're not getting good performance, check your algorithms; just as in any serious language.

Related Topic