Optimizing a general Minecraft instance - gsquaredxc/hyskyAPI GitHub Wiki

There are a few tricks we can use to optimize Minecraft.

Upgrading JDK version

The bundled JDK with Minecraft is fairly old, having expired on October 20, 2015. In 2021, we can do slightly better. The recommended switch is to JDK 16, and this will dramatically improve performance. AdoptOpenJDK offers the primary build for this. AdoptOpenJDK has instructions for how to install JDK 16 onto your machine.

You must also switch your Forge version to a patched forge version, since there were some hacky things in Forge that prevent directly running on JDK 16 (despite the well known ability of Java to support backwards compatibility). GitHub Actions powered builds are available via my fork. The installer works exactly like the official forge installer.

After installing JDK 16 and the patched version, you should either create a new installation, or use your existing one. You should switch your Forge version to 11.15.1.0 (the one provided by my build) and you should switch your java executable to the new one. This exact value depends on your OS, but for Windows it should be roughly around C:\Program Files\AdoptOpenJDK\<version>\bin\java.exe and on MacOS it will be /Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/bin/java.

This change should provide significantly more frames and better overall performance, but incorrectly programmed mods may have issues with the version change. If this is the case, first attempt to get into contact with me, and I can attempt to diagnose the problem. The maker of the mod may be able to fix the problem as well.

Understanding your performance issues

In order to make more specific changes to improve performance, performance issues must be diagnosed. In Java, there are a few bottlenecks. With rendering, GPU can be a concern but I do not believe that GPU tends to be the performance issue in Minecraft.

CPU has two bottlenecks. Single core performance is the usual bottleneck. Most of the Minecraft client is on a single core, so if your single core performance is lacking, most of Minecraft will have issues as well. Multi-core bottlenecks are very rare, however a large part of Java does use multiple cores. Without explaining the entire Java backend, giving Java more cores will allow it to do things to make the single core performance better.

RAM is a fairly big deal in Minecraft and tends to be the focus of a lot of optimization. Java uses Garbage Collection (GC), which finds all the RAM not being used and allows Minecraft to use that RAM again. In order to find RAM issues, a simple look at F3 will inform you of your situation. GC can do a lot of things on a different thread, however at certain times it must stop the main process to remove the garbage. Most of the time, this occurs very very quickly (<1ms), whereas a frame (60fps) occurs every ~16.6ms. If GC is incorrectly configured, you may see larger pauses either every GC cycle, or every few GC cycles. When watching your F3 screen, watch for when the RAM used resets to a lower number.

RAM optimizations

Used RAM percent is too high

After a GC cycle, if your RAM used drops to a number close to the cap (1900MB/2048MB), you will have GC cycles often. Additionally, if you hit 2048/2048 ever, your GC will have to stop everything (STW) to clean up. This is VERY bad, and will cause your game to freeze. The easiest fix is to allocate more RAM via changing -Xmx2G to a higher number.

Used RAM is too high

If you have limited RAM or want to squeeze more performance out, you may want to wish to reduce the amount of RAM that Minecraft uses. The easiest trick to do this is to use string deduplication -XX:+UseStringDeduplication. String dedup is done entirely by other cores on your computer and will not ever decrease your FPS. Additionally, for Minecraft it can squeeze a large amount of RAM out. This trick can only be used with Shenandoah and G1.

Switching GCs

If you have performance issues of any sort, or want to see if you can improve performance, try switching to different GCs. Minecraft by default uses G1GC, but Shenandoah and ZGC are good alternatives included in newer JDK versions. -XX:+UseShenandoahGC and -XX:+UseZGC. Note that you may need to mess with the settings of each GC in order to reach the full performance of that specific GC.

Allocating memory beforehand

-XX:+AlwaysPreTouch asks your OS for the RAM you requested all at the same time rather than in batches. This may prevent lag spikes when you are initially playing, and generally should improve the performance of your game. However, it will force the system to give Minecraft the entirety of the RAM you asked for, which on low RAM machines may end up causing issues.

Do note all performance optimizations tend to be system specific, so something that works on one computer may not work on another. The best solution is always to test on your machine to determine if something is beneficial. In general, something that works on your friends machine will work on yours, however the internals of specific CPUs does affect how a specific change will affect your computer. (Size and design of BTB, etc)

⚠️ **GitHub.com Fallback** ⚠️