top | item 29330109

GC progress from JDK 8 to JDK 17

318 points| carimura | 4 years ago |kstefanj.github.io | reply

190 comments

order
[+] dandotway|4 years ago|reply
As Java is generally the fastest GC'd language, what's the current state of Java gamedev?

Once upon a time, this indie Java game called Minecraft became the most successful game of all time.

But from the few minutes of research I just did, Java cannot be deployed to many commercially important systems

  - Nintendo Switch
  - PlayStation
  - iOS
It appears Java is only still viable for Windows and Android, and the 1% Linux desktop market.

There used to be the GCJ project which would in theory let you run Java anywhere you had a C/C++ compiler, but Oracle's litigiousness killed that because the Java[TM] "platform" must run the official Java[TM] bytecode.

It appears C# via Monogame lets you deploy to all desktops (Win/Mac/Linux), mobiles (iOS/Android), and consoles (PS/Switch/Xbox). So ironically C# seems to now be the "write once, run anywhere" fulfillment of the original Java promise.

[EDIT: grammar.]

[+] kllrnohj|4 years ago|reply
Java's FFI and value type situation are the two major missing pieces for Java gamedev. C# has better stories for both, and has from the beginning.

Don't confuse Java having the fastest GC with Java being the fastest GC'd language (especially not in all situations)

[+] admax88qqq|4 years ago|reply
Seriously, with sub-ms pause times of ZGC you could run a GC every frame and have tons of time to space for actual processing.
[+] winrid|4 years ago|reply
You can compile to iOS/Android with libgdx.

I've been doing this with a game I'm building that has a custom 3D OSM map renderer.

[+] 3371|4 years ago|reply
Well, Minecraft is notoriously slow, but I guess that's very much nothing to do with Java, but the un-optimized code... Have seen quite some developers criticizing Mojang for this.
[+] rurban|4 years ago|reply
Did Java already beat Common Lisp and C#? I doubt so. Esp. since the commercial lisps with much better GC's are not listed on the benchmarkgame. But also not Shenandoah, and the other commercial Java GC's
[+] KronisLV|4 years ago|reply
> As Java is generally the fastest GC'd language, what's the current state of Java gamedev?

In my eyes, there are no truly viable options out there, mostly due to a lack of approachable GUI game development software or toolkits.

For example, compare the one option that comes close, jMonkeyEngine (https://jmonkeyengine.org/) to the likes of Unreal (https://www.unrealengine.com/en-US/) and Unity (https://unity.com/), or even Godot (https://godotengine.org/).

Sure, many out there enjoy developing games in a code first approach, or even writing their own engines (e.g. Randy, whose videos are pretty interesting and comedic: https://www.youtube.com/c/RandytheSequel/videos or https://www.youtube.com/c/RandallThomas/videos), but i'd argue that the success of an engine largely depends on the popularity that it gains, which is largely influenced by how easily approachable it is.

Java game development doesn't have such a tool or set of tools, even the activity on jMonkeyEngine's GitHub (https://github.com/jMonkeyEngine) is really low, compared to that of Godot (https://github.com/GodotEngine), even if the technologies themselves could be used to similar degrees of success in many situations.

Come to think of it, it would be nice to actually benchmark something like Unity (C#), Godot (C#), Godot (GDScript) and jMonkeyEngine (Java) in similar real world applications, to see how they fare, performance, resource usage and development speed wise.

My intuition tells me that Java would be faster than GDScript, which would make talking about its (and also Java's, and thus also C#'s) performance a moot point for many of the indie games out there, since GDScript's slowness doesn't prevent many wonderful games from being developed in Godot, here's their latest showcase reel: https://www.youtube.com/watch?v=iAceTF0yE7I

[+] aetherspawn|4 years ago|reply
Is Java GC (“the best”) really that much better than something with immutable heap ie Haskell?
[+] chickenbane|4 years ago|reply
> It appears Java is only still viable for Windows and Android, and the 1% Linux desktop market.

Funny how you frame Java "only" being available for some of the most popular platforms, which is billions of devices.

[+] twic|4 years ago|reply
Shame this doesn't show the CMS collector, which was present in 8 and 11, but removed before 17. CMS was the go-to option for low-latency collection for a long time, so it would be good to see how it compares to the modern options.

It would be particularly interesting from the perspective of someone working in a shop which still has lots of latency-sensitive-ish workloads running on JDK 8 with CMS!

[+] jesboat|4 years ago|reply
I'm curious what your applications' allocation patterns are like.

I've worked on a couple projects where switching from CMS to G1 was a pretty big latency win. Most of the were pretty strongly request-response-based. Pretty quickly G1 would converge on having most of the regions being young, and, by the time G1 wanted to do a mixed collection, most of them would have no live objects and would be summarily killed.

[+] lmilcin|4 years ago|reply
Also, it would be interesting to see this progression from at least 1.4. By the time 1.8 was released I had the impression that GC is already pretty well optimized for throughput.
[+] zokier|4 years ago|reply
Shenandoah GC is conspicuously missing despite having similar availability to ZGC and competitive performance characteristics.
[+] maxpert|4 years ago|reply
I've used Shenandoah GC with great success and I recommend anyone considering ZGC (specially on Kube and container environments) to try Shenandoah first. You won't have to do additional work to enable large pages, yet your performance is pretty close.
[+] papercrane|4 years ago|reply
It would be good to see the numbers, but I suspect the reason is just that the author used the Oracle build of OpenJDK which doesn't include it.
[+] bob1029|4 years ago|reply
As a .NET developer I am a little envious of all the GC knobs that Java developers get to play with.

If I could have only 1 new GC thing from Microsoft, it would be the ability to totally disable GC during the lifetime of a process. I don't even want to be able to turn it back on.

I have a lot of scenarios where I could get away with the cruise missile approach to garbage collection. No reason to keep things tidy if the whole world is gonna get vaporized after whatever activity completes. Why waste cycles cleaning things up when you could be providing less jitter to your users or otherwise processing more things per unit time?

[+] google234123|4 years ago|reply
Is the .net gc still contained in one gigantic source file?
[+] vletal|4 years ago|reply
I like how this reached the top page soon after "Go does not need a Java-style GC" (https://news.ycombinator.com/item?id=29319160).

Moreover, are the significantly lower GC pause times help improve snappiness of GUI apps, such as IntelliJ IDEA?

[+] pjmlp|4 years ago|reply
The GC might help, but it doesn't do magic when threads aren't used the correct way, too much stuff lands on the UI thread or synchronous IO is used all over the place.
[+] edgyquant|4 years ago|reply
That’s the magic of HN (or maybe it’s a form of the Baader-Meinhof Phenomenon.) When one topic reaches the front page it seems like a couple more based around it hit the front page the same or next day, which allows us to expand on what we’ve learned.
[+] Sankozi|4 years ago|reply
Snappiness problems are often due to lazy loading Java classes.

For example first time loading project settings takes 1+ seconds while next less than 0.5. This value might get lower later if JVM decides to optimize more some parts of UI application.

[+] fnord123|4 years ago|reply
Current IntelliJ uses Java11 and has gotten slower over the past few years (anecdata from my own use) - so probably not.
[+] msie|4 years ago|reply
I’ve given up on IntelliJ and java-based UI’s long ago. So disappointing.
[+] pjmlp|4 years ago|reply
Note, only relevant for OpenJDK and the JVMs based on it, there are other GC available to other JVMs, including real time ones.
[+] tannhaeuser|4 years ago|reply
graalvm and graalvm's svm/native-image as well, the latter having only SerialGC, with G1 in EE only, and crashing ;(
[+] pkoperek|4 years ago|reply
Genuinely interested - could you share some good resources about it?
[+] seanwilson|4 years ago|reply
How much do you need to worry about the GC causing frame stuttering when writing games now? Object pools are still important?
[+] zokier|4 years ago|reply
Well, jdk17 was released just few months ago so I doubt anyone has real experience with it for gamedev. But considering that game heaps are relatively small (as in <100G) and modern Java GCs can manage consistent <1ms pause times, I'd imagine Java is more viable for gamedev from that point of view. I'd also emphasize that there is large spectrum of performance requirements for games and you can make quite a lot these days with relatively poor performance characteristics, and on the other hand in the top end Java probably is still not good enough.
[+] jimsimmons|4 years ago|reply
These GCs have a 1GB overhead when working with a 16GB heap. That’s 6% of your available memory. I was expecting modern GCs to be way more efficient so I’m kinda shocked this is what state of the art is.

I also wonder how much of the progress to “Sub (200) millisecond” latency target is due us just having faster machines. I honestly have no model to tie this to actual performance of my code. I guess it translates but not really sure how.

Not bagging on Java —— I am just surprised how inefficient an industrial strength GC can be. I understand why manual memory management still holds its own now.

[+] gregaccount|4 years ago|reply
Looking at that, why isn't ZGC the standard GC in Java 17?
[+] jbellis|4 years ago|reply
One of the graphs shows ZGC with almost 50% more overhead (in heap space) than G1, which could very well take some applications from "works fine" to "broken." So I can see why they'd leave it something to opt in to.
[+] kaba0|4 years ago|reply
Latency and throughput are fundamentally opposite ends of the same axis. And perhaps the majority of Java applications prefer better throughput.
[+] vips7L|4 years ago|reply
G1 is probably still a better choice as it "balances throughput and latency". ZGC also wasn't generational until recently.
[+] Rovanion|4 years ago|reply
Absolute gc throughput and overhead.
[+] Thaxll|4 years ago|reply
What is not shown is those benchmark is how much CPU is used for each GC. For example the latency for ZGC is much lower but does it means it uses more CPU than G1.
[+] thomascgalvin|4 years ago|reply
Those latency and pause-time numbers are pretty sexy. 200ms is still probably too high for some applications, but for everything I work on, this is incredible.
[+] mcdonje|4 years ago|reply
The throughput & latency charts have JDK8 pegged at 100%. Since that's meaningless and the value is in the difference between the JDK versions, it should be represented as a delta.
[+] ozim|4 years ago|reply
Which does not matter because most of stuff still rides Java 8.
[+] slater|4 years ago|reply
Might wanna save some bandwidth with that 1.25meg yet small-in-visual-size portfolio.png, yikes! XD