4 ms·
I have an IAQ of my own: Why is it that Java VMs seem to have such different interactive latency when compared to other memory-managed language VMs? Is the per
by nailer 15y ago
I have an IAQ of my own:
Why is it that Java VMs seem to have such different interactive latency when compared to other memory-managed language VMs? Is the performance of eg, eclipse or Android or the Java browser plugin something to with the GC kicking in too aggressively?
Over the last decade I've heard different explanations re: SWT/swing/AWT toolkits, and server-side optimizations being default in desktop VMs, but I'm fairly sure both issues should be resolved now. Nevertheless, my general experience seems to be if it's Java based, it seems to handle touch/mouse events noticeably worse than otherwise.
Maybe .net and Python and the rest are doing more of their UI work in C?
- mbell 15y agoThis has a lot more to do with the GUI toolkits than the JVM. Python is most often used with bindings for GTK (C), QT (C++) or tk (C). I don't know a lot about .net but I believe it just links to the standard windows gui toolkit probably also written in native code. For Java the main issue is that Swing/SWT/AWT suck and java is mostly used as a server language so there is little impetus to fix them. Eclipse is just bloated, that is why its often slow. Android has its own custom JVM (Dalvik) but I imagine the majority of the UI rendering / handling code is native with Java bindings. All that said, the full JVM (both openJDK and sun's) have multiple garbage collectors and many tuning options. This creates flexibility to tune the GC for particular work loads but also makes them complicated to work with. It doesn't help that the default GC/memory settings in the JVM are a bit...off, and use the high throughput GC vs the low pause collectors.
- nvarsj 15y agoIt's pretty simple... Hotspot collectors are optimized for throughput, not latency. That's where the money is for Sun/Oracle. It's a trade off between one and the other in any garbage collector. You can tune it to some extent.
- lars 15y agoIt's been a while since I've done work in Java, but I'm pretty sure the GC is not to blame for this. Java uses a concurrent mark and sweep GC. The concurrent part means it does not pause the world while it's collecting. So as mbell says, it has to do with the UI frameworks. But I don't think it has to do with whether or not the UI code is written in C either. In the UI frameworks I've used for both Python and Ruby, you could write slow interpreted code that would run on the UI thread. The key thing was you tended not to do it, because the frameworks didn't encourage you to do so. The problem is that Java frameworks make it easy to for example do IO on the UI thread, whereas the other frameworks make it hard. Threading is relatively hard to get right in any of these languages, so the choices made by the framework authors really matter. Another thing contributing to Java being perceived as being slow is the long boot time of the JVM. (It used to be slow at least, don't know if it still is.)
- mbell 15y ago> It's been a while since I've done work in Java, but I'm pretty sure the GC is not to blame for this. Java uses a concurrent mark and sweep GC. Part of the problem is that the default GC is not the ConcMarkSweep collector in most installations but rather its the parallel "stop the world" GC that is optimized for throughput, not latency. For web applications (or anything with latency issues) step one is almost always to modify your JVM opts to enable the CMS collector. Unfortunately even the ConcMarkSweep collector can have issues. Its not that hard to create a workload that it can't handle resulting in your app slowing eating through all available heap space because the collector can't keep up ultimately forcing a full collection which on large heaps can be devastating, think 60 to 120 second pauses. The G1 collector, which is no longer considered experimental in Java 7 is 'better' and you can specify a maximum pause time, but it can still run into situations where it has to force a full GC and there are situations where the CMS collector is still better.
- sehugg 15y agoIt's the libraries. Write an app with OpenGL or SDL and it works fine. (Minecraft is a perfect example)