3 ms·
Many of the tricks discussed here come for free with static typed compilation + JIT. All those tedious type annotations are good for at least one thing, it seem
by KirinDave 16y ago
Many of the tricks discussed here come for free with static typed compilation + JIT. All those tedious type annotations are good for at least one thing, it seems.
I'd think the #1 thing balancing this right now is the overhead of the GC. No matter how good a GC we get, it's still going to be more costly than well-written direct memory management except in degenerate cases.
- bad_user 16y ago> come for free with static typed compilation + JIT NO. Static typing doesn't help when speaking about inline caches for virtual calls (most method calls in a typical Java app) ... it only helps on the initial method lookup because you're dealing with a vtable instead of a hash (that's because at least you know the interface at compile-time). But to do code-inlining and other such optimizations, the Hotspot JVM only compiles bytecode that has been profiled. That's because jitting itself is an expensive operation and you can't just redo it after you've inferred the conditions of a potential call-site cache, being more efficient to just first interpret that code until you have enough data. Thus the long warmup time. But what works in a desktop/server environment doesn't necessarily work on a mobile phone with much less constrained resources ... and unfortunately Moore's law in the mobile world goes to increased battery life instead of increased processing power / bigger or faster RAM. I still think Java was a poor language choice for Dalvik precisely because methods in Java are implicitly virtual and because you can't have custom stack-allocated values. A language like C# would've been more suitable ... but since its their VM, maybe they'll provide an efficient alternative.
- KirinDave 16y ago> NO. Static typing doesn't help when speaking about inline caches for virtual calls (most method calls in a typical Java app) ... it only helps on the initial method lookup because you're dealing with a vtable instead of a hash (that's because at least you know the interface at compile-time). Are you sure? I thought in certain conditions Java could dispense with the vtable lookup even in interpreted land. Not that it matters nearly so much there. > But to do code-inlining and other such optimizations, the Hotspot JVM only compiles bytecode that has been profiled. That's because jitting itself is an expensive operation and you can't just redo it after you've inferred the conditions of a potential call-site cache, being more efficient to just first interpret that code until you have enough data. So you're saying the Dalvik JIT does not do this? The reason I said "static typed compilation + JIT" was because, in my reading of the literature anyways, at jit time it could dispense with the vtable lookup if it's seen a stable type signature. > I still think Java was a poor language choice for Dalvik precisely because methods in Java are implicitly virtual and because you can't have custom stack-allocated values. A language like C# would've been more suitable ... but since its their VM, maybe they'll provide an efficient alternative. Please no. C# has, unsurprisingly, evolved into an absolute soup of a language. It's a crud-infested nightmare. The only thing saving me from absolute insanity these days is the slow migration to F#. But really, since our comparison is to Objective C, where all calls are method dispatch which is a slightly more expensive than java calls, I don't think we're losing much. At best, Java is slightly faster. At worst, Java uses the same technique (or is interpreted, but again it doesn't seem to be losing that badly in this mode).
- 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 ago