3 ms·
> Not for calls to virtual methods, especially those call done through an interface ... you can't infer the right method to call at compile time when you don't
by KirinDave 16y ago
> Not for calls to virtual methods, especially those call done through an interface ... you can't infer the right method to call at compile time when you don't know the object's real type.
Yes. I think we've actually been arguing the same point and just stating it differently. My original argument was that the Java way is actually always as fast and potentially faster than the ObjC way. Everything that works for ObjC works for Java, but java has semantics that allow for further optimization without breaking the required behavior of message passing.
> I don't think having your custom stack-allocated values or having pointers in "unsafe" portions of code (which really is a lot safer than doing JNI) is that big of a deal, and can help a lot in constrained environments.
I wonder. Most GCs are doing allocation that is only an instruction or three (I don't know what it'd look like on ARM) more overhead than incrementing the stack pointer. The CLR is somewhat famous for this. It is a bit of a bummer that you lose prescriptive-layout for structure types in java, though.
- bad_user 16y agoYeah, allocating / deallocating short-lived objects in Java has an almost zero cost (read about it in some article, can't remember which one). But that's not the point ... stack-allocated values help with mathematics, like boolean comparisons, matrix multiplication or just plain arithmetic, because otherwise you have to box/unbox those values. Software that relies on that (graphics / animations come to my mind, but not only) ... can take a big performance hit. And even if the GC is very efficient, you can still strangle it with many small objects, and sometimes those objects aren't deallocated fast enough. Stack allocation/deallocation is much more predictable for lots of small objects. But I think you already addressed this point.