3 ms·
> thought in certain conditions Java could dispense with the vtable lookup even in interpreted land Not for calls to virtual methods, especially those call don
by bad_user 16y ago
> thought in certain conditions Java could dispense with the vtable lookup even in interpreted land
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. And in Java you can also load new classes that implement a certain interface at runtime ... and this also makes optimizations more difficult.
Now of course ... for calls to static functions or for calls on methods marked as "final" Java can and does dispense of the vtable lookup.
Unfortunately in Java methods are implicitly virtual, as you have to explicitly mark them as being final (for performance, although as far as language design for the stuff I do, I like it).
> Please no. C# has, unsurprisingly, evolved into an absolute soup of a language
I meant ... just as high level as Java, but with lower level capabilities here and there (where it matters). 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.
- 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.