4 ms·
Faster than ObjC? Unless your objc code is written using nothing but id and reflection, I’m not sure how can this be the case...
by sheeshkebab 8y ago
Faster than ObjC? Unless your objc code is written using nothing but id and reflection, I’m not sure how can this be the case...
- saagarjha 8y ago> Unless your objc code is written using nothing but id and reflection That's how all Objective-C code is written–every method call goes through objc_msgSend.
- sitharus 8y agoTo be fair to objc_msgSend it's orders of magnitude faster than most reflection APIs. https://www.mikeash.com/pyblog/performance-comparisons-of-common-operations.html https://www.mikeash.com/pyblog/performance-comparisons-of-co... has some benchmarks, it's a bit old but I don't think objc_msgSend would get slower.
- saagarjha 8y agoYup, I'm not saying objc_msgSend is slow: it's just that it's not faster than a direct call, and I believe about on-par with a virtual function call.
- Derbasti 8y agoAnd let's not forget that ObjC is downwards compatible with C. If you need a particular loop or function to be fast, you can write it in C, in the same ObjC source file.
- archagon 8y agoFor one, ObjC can't treat objects as values or initialize them on the stack. Also, the everything-is-an-object paradigm is terrible for arrays of values, since every NSNumber or NSValue has to be individually malloced and released. (Though maybe not the case anymore? It was certainly a chokepoint several years ago.) Both of these factors have forced me into using lower-level Objective-C++ code on numerous occasions.
- mercutio2 8y agoNSNumbers are generally tagged pointers, unless you’ve got a really large number.
- deleted 8y ago[deleted]
- archagon 8y agoThis didn't help me in my app, unfortunately, because I needed to encode CGPoints as NSValues. I suppose I could have resorted to ordinary, interleaved CGFloats, but it was way easier and more productive to just use C++ vectors. I knew exactly what I was getting with those, and I didn't have to do the boxing/unboxing dance.