There has been a fair amount of talk throughout the community recently about how upcoming versions of Java will massively improve Minecraft's performance. While we can't yet benchmark these changes, we can explore what changes are coming, when they'll likely arrive, and how they're likely to affect Minecraft and servers. This article is for both users and developers, so I'll skip over the finer technical details to make it more understandable. In saying that, I will use some technical terms with explanation when necessary.

Currently, Java 8 is the recommended version of Java for Minecraft. While it's possible to run on newer versions, and many servers do, Mojang officially recommends Java 8. This recommendation will likely change in the future as some of these changes come to Java. Due to this, the article will also include some released features in versions of Java beyond Java 8.

Garbage Collectors

The most short term changes that will improve Minecraft are changes to the garbage collector. A garbage collector is a system that cleans up any memory that the application is no longer using. While it may seem simple, these are very time-intensive and complicated pieces of code. With every Java release, there are improvements to the included garbage collectors.

G1GC

As of Java 9, a newer garbage collector known as the G1 Garbage Collector has been the default. While available in Java 8, it wasn't the default. This garbage collector performs significantly better with Minecraft than the old default, and even more so with improvements that have come to it since it became the default. The improved garbage collector is one of the main reasons many servers use Java 11 over Java 8. Members of the Minecraft server community, such as Aikar, have also done a fantastic job of tweaking the G1 garbage collector and documenting their findings.

Shenandoah and ZGC

G1 isn't the only new garbage collector. Both Shenandoah and ZGC have come about in recent versions of Java and boast rather impressive performance stats. While both of these appear to run faster than G1 in general use cases, they have not been heavily researched or tested on Minecraft servers. Due to this, using G1GC with Aikar's tweaks is likely a better idea unless you wish to perform some experimentation. Shenandoah is significantly more likely to be a better garbage collector for Minecraft than ZGC, however, as it is more optimised for the kind of memory output that Minecraft creates.

Project Panama (Native Access)

Project Panama aims to improve the way Java applications access lower-level aspects of the machine. In software such as Minecraft, these low-level accesses generally refer to networking hardware or graphics cards. Most of Panama's contents will arrive as preview features in Java 16, to hopefully receive full release shortly after.

Libraries

This project will not directly impact Minecraft, but some of the game's dependencies can improve performance by utilising Panama. The most significant benefit is on the client, where the rendering library the game uses (LWJGL) can make use of Panama to improve performance. The networking library in the game (Netty) will also likely see a minor improvement, as Java will be able to optimise the code better. As the affected part of the network code in the game is not slow, this will likely not be too noticeable.

Proxy Software

However, one area where Panama is likely to have a significant impact outside of Minecraft is server proxy software. Server proxy software spends almost all of its time handling network requests, so a version of Netty that makes use of Panama could theoretically take a more considerable number of players per proxy.

Project Loom (Virtual Threads)

One of the Java changes likely to come out soon is the virtual threads feature from Project Loom. This feature provides a fast and straightforward way to make small tasks asynchronous or multithreaded. While this will not allow the game to be entirely multithreaded like I've seen some claim, it may improve performance and simplicity of some areas that are already multithreaded such as lighting, networking, or chunk loading (on Paper).

Another massive bonus is that it will hopefully make it easier for programmers to do the correct thing when writing asynchronous or multithreaded code. This change may mean that more beginner programmers will write plugins for servers that properly use threading and asynchronous code, especially in a safer manner.

Recent information indicates that this feature could land as a preview as early as Java 17, but it will likely be a release or two later before it becomes stable. Overall, this feature will not improve much, but if the game is changed to make proper use of it, there may be some minor performance improvements.

Project Valhalla (Inline / Value types)

Project Valhalla has somewhat become a familiar name through some areas of the Minecraft server community, with claims that it'll majorly improve the performance of Minecraft. The main feature of Valhalla that'll impact Minecraft is Inline Types, formerly known as Value Types.

Currently, the Minecraft codebase is full of containers of memory that store smaller values inside of them. For example, a block position contains three numbers to refer to the x, y, and z coordinates. Without inline types, this container itself takes up memory, as well as the contents. With inline types, the container can exist in the code but act as if it doesn't exist, only using memory for the contents. This change leads to less memory usage, quicker memory allocations, and less work for the garbage collectors.

While inline types likely won't be a "game-changing" improvement, this can improve the game's performance majorly. Like most of these Java changes, however, this requires Mojang to make the most of it. Valhalla is likely the most significant feature coming to Java in the future from the perspective of Minecraft; however, don't expect it anytime soon. Adding inline types to Java requires a fundamental change to the way it works, as well as ensuring that it doesn't break any previous behaviour.

Conclusion

The future of Java contains some exciting changes, and some can improve Minecraft for the better. However, these improvements depend on Mojang updating to a new version of Java and making changes to the game's code. Hopefully, at some point, the potential benefits outweigh the time commitment, and Mojang dedicates the time to achieve this. While Mojang has quietly added support for the Minecraft launcher to supply newer versions of Java, until they officially announce a Java version bump, we can only assume the game will remain on Java 8 for the foreseeable future. Until then, you can at least try out the new garbage collector improvements.

This article is part of a series on how to run a Minecraft server. Click here to check out more!

Want to help me write more posts like this? Check out my Patreon!