Performance Optimization

From TerraFirmaCraft Plus Wiki
Revision as of 09:13, 20 January 2023 by Sanguine Sloth (Talk | contribs)

Jump to: navigation, search
Other languages:
English • ‎русский

Overview

Minecraft 1.7.10 is known to have some performance issues compared to other versions, and this is made even worse by the fact that TerraFirmaCraft utilizes the full 256 world height. Your system may be able to play other heavily modded instances of Minecraft with no issues, but when it comes to TerraFirmaCraft it's like comparing apples to oranges. In vanilla Minecraft, as well as 99.9% of all modded Minecraft, the sea-level of the overworld is at y=63. In TFC, sea-level is all the way up at about y=140. That means that in every chunk (which is an area of 16x16 blocks), there are about 20,000 more blocks to load. There are also a handful of other things that make TFC much more resource intensive, so this page is a guide to help make the game run as smoothly as possible. It is strongly recommended that you go through all of the following categories, as they are generally equally important in improving performance.

Performance Optimization Within Minecraft

Due to the way TFC+ extends the capabilities of Minecraft, it is more difficult to run than vanilla. When playing on weaker computers (minecraft is almost completely CPU dependent) it is recommended to turn smooth lighting to minimum, but never off as this can cause graphical glitches with TFC+ blocks (mainly roof items). You may also benefit from reducing particles, and reducing render distance.

Performance Optimization Using JVM Arguments

Minecraft is coded in a programming language called Java. This programming language is different from the ones that you will usually have in the programs of your system. One key feature is the "Java Runtime Environment" which is sort of like an operating system within your operating system (in very simplistic, non-technical terms). It can be configured using what are called 'JVM arguments' in order to change its behaviour.

JVM for Default Minecraft Java

Minecraft itself ships with a bundled version of java for each minecraft version. for 1.7.10 this is Oracle java 8_51, the last version before Oracle changed their licensing.

For this version of minecraft, on systems with 8GB or more memory, we recommend:

 -Xms2G -Xmx4G -XX:NewSize=1G -XX:MaxNewSize=2G -XX:SurvivorRatio=2 -XX:+DisableExplicitGC -d64 -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts

for systems with 4GB ram, use:

 -Xms1G -Xmx2G -XX:NewSize=512M -XX:MaxNewSize=1G -XX:SurvivorRatio=2 -XX:+DisableExplicitGC -d64 -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts

if you are on a 32-bit system, do not use -d64, as this forces Java to run in 64 bit mode and will not work on your system.

JVM's for Alternative JRE's of Java

As Java is open source, there is more than one fork of it in development. Several companies have made different products that offer lower latency garbage collection than Oracle's Java. Keep in mind that Minecraft 1.7.10 can only run in Java 8, and will fail to launch on any newer version. To make Minecraft use alternative JRE's, simply point the launcher to the Java executable through the menu right above JVM arguments. The executable is located in /bin.

This method offers significant performance benefits in the %1ile and %0.1ile of FPS, and as such reduces stuttering significantly. This is especially true when used together with Optifine.

Windows

We recommend that you install Red Hat's build of OpenJDK JRE8, by downloading the zip file and unpacking it in a directory you know the location of. Recommended arguments are:

 -Xmx4G -Xms4G -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+AlwaysPreTouch -XX:+DisableExplicitGC

Azul C4 does not work in Windows, and will crash if another GC isn't explicitly called. It is strictly Linux kernel only.

Linux

If you are a user of Fedora (v.24+) or RHEL (v.7.4+) your default repositories offer the same Red Hat builds recommended in the windows section, simply use the same arguments. As of July 2022 Redhat has started to release tarballs for linux along with windows, so you may download it from their website.

If you are a user of other distros of Linux (or would like to experiment outside Red Hat), you can instead use Azul's builds for Java 8 available on their website. Simply download the tarball and untar to a known location. Recommended arguments are:

 -Xmx4G -Xms4G -XX:+UnlockExperimentalVMOptions -XX:+AlwaysPreTouch -XX:+DisableExplicitGC
 

Azul Defaults to C4GC, their own pauseless garbage collector.

MacOS

There is currently no known vendor that offers ShenandoahGC on Java 8 that has prebuilt packages for MacOS. You would have to compile it yourself. Please contact @Space_Sloth on the official discord if you manage to produce a build, as we have not yet been able to reproduce Red Hat's builds.

Explaining The Options

This part of the page is quite technical, and will delve into Oracle/Red Hat/Azul Java documentation at times. Knowledge of this section is not necessary to continue through the guide, and you may skip it.

The main functions of JVM arguments are 2 things, to allocate RAM to the JRE (in this case, running minecraft) and the control the garbage collection of Java. Garbage collection is the technical term referring to the cleaning of unused items that are in the allocated RAM to free them up for other uses. In most other programs of your computer (often written in the language of C or C++) this RAM allocation to functions are handled manually or semi-manually. In Java, the garbage collector will run to automatically handle it, at the cost of momentarily stopping or slowing the program down as the GC moves through the list checking their usefulness. This greatly reduces development time and potential bugs, but can cause stuttering issues in a game (where a frame is ideally drawn every 16.67ms and garbage collection can take up to 500ms). In Minecraft specifically, the RAM allocation happens in the young generation extremely rapidly, and the garbage collector must focus on culling the young generation to avoid major GC.

There are 4 types of GC's (Garbage Collectors) within this wiki article. G1GC is the default option for minecraft (and java 8) and offers the worst performance in our testing. Concurrent Mark Sweep is the recommended GC for Minecraft defaults and offers better performance in all aspects compared to G1GC, and the highest average FPS. Shenandoah is a Red Hat project for low latency GC, and offers the smoothest results (best %1 and %0.1 lows) in tested systems. C4GC is the propriety solution by Azul that offers a "pauseless" GC for Linux. It performs similar to Shenandoah (though no direct comparison in the same OS has been made yet).

G notates Gigabytes, M notates Megabytes in arguments. Due to Minecraft (1.7.10) not being coded to handle arbitary sizes of RAM, it isn't recommended allocate all of your system ram to it. This can actually cause it to slow down. You can check the level of usage in the top right of the F3 menu. Try to keep the usage between %40-%80. In our testing for single player clients allocating more than 4GB ram seems to cause measurably worse performance (-%20) with TFC+ and basic QoL mods. Modpacks may require more.

-Xms is used to set the minimum memory (initial heap), and -Xmx is used to set the maximum memory (maximum heap) allocation. In G4GC and ShenandoahGC, the documentation recommends that Xms and Xmx are the same.

-XX:NewSize and -XX:MaxNewSize should be set to 25% and 50% of -Xmx for CMS respectively. They denote the New generation size. Do not use these options for the other GC's.

-XX:SurvivorRatio= denotes the ratio between each survivor space and eden space after GC is run. Eden space is the pool from which memory is initially allocated for most objects, together with 2 survivor spaces they make up the "young generation". This is a CMS option.

-XX:+DisableExplicitGC disables calls to System.gc() in order to reduce how often GC must be run. This is usefull in all cases.

-d64 forces java to use the 64-bit version in case you have a lingering installation of 32-bit. Do not use this argument if you are on a 32-bit operating system.

-XX:+UseConcMarkSweepGC/-XX:+UseShenandoahGC denotes the type of GC that should be used. CMS has been deprecated in Java 9 (Minecraft 1.7.10 runs in Java 8). Do not use this argument for 1.12 or newer, it explicitly does not work in version 1.17.

-XX:+AlwaysPreTouch: Goes through all of the allocated RAM space to check it at startup instead of doing it partially during runtime, slightly increases startup times at the benefit of performance. Both ShenandoahGC and C4GC explicitly recommend this.

Unused Options

-XX:MaxGCPauseMillis=<N>: sets a garbage collection maximum pause target based on n being milliseconds. Automatically tries to adjust heap sizes to meet demands.

-XX:GCTimeRatio=<N>: similar to previous command, but n denotes 1/(1+n) in garbage collection/program time. Default value is 99 for %1 of time spent in GC.

These arguments pop-up in online recommendations for JVM arguments occasionally. We do not recommend that you use them, as they do not entirely help the game run any better, especially with the values recommended online.

-XX:ParallelCMSThreads and -XX:ParallelGCThreads (and other Parallel Thread Arguments): sets the amount of CPU threads that the respective phases of garbage collection will take. Automatically adjusted by JVM according to your CPU cores. Marginal gains from specifying if any (could even lose performance by manual adjustment). We do not recommend that you touch these at all.

Performance Optimization Using Mods

There are mods that have been made to optimize minecrafts code and extend it. This is especially useful in older versions like 1.7.10 that do not have the recent optimizations done in newer versions.

Fastcraft

Fastcraft is a mod that optimizes the mathematical functions that minecraft uses in order to increase FPS. Since this guide will also walk you through installing Optifine (and setting it up to work with TFC) it recommends that you use version 1.25 (latest as of last check). Simply place the mod in your mods folder.

Optifine

By default, Optifine can cause graphical issues with TFC+ due to the rendering methods used. Without proper configuration most performance functions cannot be used. Firstly, download optifine. Make sure to get the 1.7.10 version OptiFine HD U E7 (latest 1.7.10 version). You'll need to click show all versions. You'll now want to download Basic TFC+ Shaders also available in addons. Starting the game up with optifine installed will let it create the folders it needs. You should now see \AppData\Roaming\.minecraft\tfc\shaderpacks. Unzip the shader into this folder, as a single folder (and not as loose files). You'll want to start minecraft and open the settings to select the basic TFC shaders for optifine, and then configure certain settings. Specifically set 'Advanced OpenGL: Fancy', 'Chunk-Loading: Multi-Core', 'Smooth FPS: On', 'Smooth World: Off', 'Fast Math: On'. More information is available on the shader github page.

For users of Nvidia graphics cards, especially on laptops, there is an extra step. You must go into the Nvidia control panel and set Java JRE/Minecraft to use the Nvidia graphics card. This is easier when minecraft is running as it'll go up to the top. You'll know it is set correctly when the optifine shader selection screen displays the name of your dedicated graphics card. If you followed the alternative JRE's method presented above, you must do this step for the JRE you downloaded.

Server JVM Arguments

This section of the wiki is currently a stub. You can help by testing it!

Since servers have to compute the game for more than one player, the amount of RAM allocated to them should be higher to compensate. Your Xms and Xmx should probably be the same in a server and be the maximum amount you can allocate to minecraft (for example total system -1GB or more). This way the garbage collector can freely work in the young generation. Example command:

 -Xms6G -Xmx6G -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+AlwaysPreTouch -jar server.jar

We prefer G1 garbage collection over CMS here due to it being more consistent in larger sizes, keep in mind that alternatives JRE's presented previously are especially better here, due to how scaling works with G1GC and CMS.


AlwaysPreTouch relates to the RAM heaps, causing greater allocation speed at the cost of JVM startup times (negligable on minecraft servers)

 -XX:+UseLargePagesInMetaspace

This option configures to Metaspace (formerly the permanent generation) to use large page adresses, easing the load on CPU cache, potentially netting significant performance. It's recommended for servers with 4GB+ RAM especially. This exact setting is not named the same for all GC's. Description of using it, and the exact names for all GC's is intentionally ommitted because you should read the manual for such options from the manufacturers. It requires you to change options within the OS/Kernel that could lead to accidental breakage if you don't know what you are doing.

Wendigo's Guide to Ancient Systems

In construction, bear with us for a moment