4 ms·
GC pauses and a very high memory usage are still a problem. That's why we don't see many Java games (Minecraft was a notable exception and ran like a dog).
by pkolaczk 4y ago
GC pauses and a very high memory usage are still a problem. That's why we don't see many Java games (Minecraft was a notable exception and ran like a dog).
- kaba0 4y agoThere are plenty of indie games written in Java, there are low-lat GCs available for the JVM (ZGC) that promises sub millisecond pauses, and you don’t have to use a ton of memory, there are ways to manage it. Minecraft was written in a very suboptimal way, its creator was a very novice developer — there are mods that easily increase performance many-many times.
- noelwelsh 4y agoThat was true about 20 years ago, but it's not really true any more. The real reason we don't see many Java games is that most games are written using either Unity or Unreal Engine, and neither of those support Java as a first class language.
- xmcqdpt2 4y agoExactly. Also both Unity and Unreal Engine have GCs and that hasn't stopped them from being used in most games. If anything, games can afford GC more than many other applications, because it's expected of a game that it will consume a lot of resources so they can just hog cores and memory and it's fine. You don't expect users to be running multiple games at the same time. Also, a lot of the more real-time work is offloaded to the GPU anyway.
- pkolaczk 4y agoThere is a difference between a GC used for only a tiny fraction of objects that implement a certain interface (Unreal Engine case) and using a GC for all the things like Java does, which you cannot opt-out. In Java case the GC has to scan gigabytes of objects, and often the garbage production rate is also in gigabytes per second, hence an efficient general purpose GC implementation is much more challenging.
- noelwelsh 4y agoYou're missing the point. There a small number of games that are extremely performance sensitive. Mostly FPS games. Java is not a good choice for these. Everything else is fine. The ZGC really does deliver on its claim. Pauses are very small (milliseconds) and it can handle heaps that are several GBs in size. However, this doesn't even matter for most games. A few pauses are fine in, say, a real time strategy game. My kids used to play Minecraft on a 10 year old Intel Mac running Java. It was good enough.
- pkolaczk 4y agoThis is still true, albeit the problems are somewhat smaller or happen less frequently. All those low-pause garbage collectors like G1, ZGC and Shenandoah make no guarantees about pauses and all of them can degrade to stop-the-world mode of operation under some circumstances, and can cause pauses several seconds long. The difference is that they do it less likely, and the old ones did it all the time. The low pause collectors also have much larger overhead in both memory and CPU than old collectors as well as traditional allocation with malloc/free. Btw, for games even a very low 1ms pause is more than 10% of frame budget, and can make the frame miss the deadline. I guess for indie games the quality bar is simply lower and occasionally missing a frame is ok.
- pjmlp 4y agoThe biggest problems are developer skills, and the perception only C with tons of inline Assembly goes. Even Unreal ships a GC.
- marginalia_nu 4y agoDunno if I'd write games in Java since it's very geared toward server coding and the clientside/gui-side of things is all but gone from the language, but Java's GC is a lot more sophisticated today than it was 15-20 years ago. You realistically won't see GC pauses at all unless you're doing something very strange. The memory consumption has also gone down considerably.