├── LICENSE
├── LICENSE.md
├── LICENSE.rst
├── LICENSE.txt
├── README.md
├── javaVersion.png
├── specialk.png
└── taskmgr.png
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 - 2023 brucethemoose
4 | Copyright (c) 2023 - 2024 Mukul Kedia
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 | ===========
3 |
4 | Copyright (c) `2022 - 2023` `brucethemoose`
5 |
6 | Copyright (c) `2023 - 2024` `Mukul Kedia`
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all
16 | copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 |
--------------------------------------------------------------------------------
/LICENSE.rst:
--------------------------------------------------------------------------------
1 | MIT License
2 | ===========
3 |
4 | Copyright (c) ``2022 - 2023`` ``brucethemoose``
5 |
6 | Copyright (c) ``2023 - 2024`` ``Mukul Kedia``
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all
16 | copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 - 2023 brucethemoose
4 | Copyright (c) 2023 - 2024 Mukul Kedia
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 | Welcome! this is a guide to tune Java for Minecraft.
10 |
11 | > [!NOTE]
12 | > 1. While these tweaks notably reduce some server and client stutters, expect only modest TPS gains + minimal FPS gains at best, and somewhat increased RAM + CPU usage.
13 | >
14 | > 2. While these flags are easy to copy-paste and forget, they are no substitute for clearing laggy things out with mods like Spark.
15 |
16 |
17 |
18 | # Performance Mods
19 | You might be thinking ***"This is weird, why are performance mods here?"*** but performance mods will increase your performance more than any Java flags could, but if you want pure performance, don't just use Optifine. There are better performing mods like [Sodium](https://modrinth.com/mod/sodium). Sodium also supports Fabric natively (unlike Optifine) and 0.6 supports NeoForge aswell.
20 |
21 | For pure performance, you can take a look at [Simply Optimized](https://modrinth.com/modpack/sop) and [Adrenaline](https://modrinth.com/modpack/adrenaline) for examples.
22 |
23 | If you want a up-to-date Optifine replacement on the other hand, [Fabulously Optimized](https://modrinth.com/modpack/fabulously-optimized) and [Additive](https://modrinth.com/modpack/additive) both mimic it very well with better performance and customizability.
24 |
25 |
26 |
27 | # Picking a Java Distributor
28 | Java runtimes from Azul or Microsoft, Adoptium, Amazon and so on are all basically identical as they are based on OpenJDK. Some notable exceptions are:
29 |
30 | 1. **GraalVM** - features a more aggressive Java compiler.
31 |
32 | 2. **Clear Linux OpenJDK** - uses a highly compatible OpenJDK base but it's build process and dependencies are [optimized for newer CPUs](https://www.phoronix.com/review/zen4-clear-linux/2).
33 |
34 | 3. **Platform Prime** - ***very*** fast since it hooks into llvm, but is currently incompatible with most mods and Linux-only.
35 |
36 | 4. **Red Hat Java 8** - has the Shenandoah garbage collector (It is the only Java 8 JDK with it).
37 |
38 | 5. **OpenJ9** - consumes less memory at the cost of being *much* slower in Minecraft. It also uses totally different flags than any other Java build.
39 |
40 | If you dont know what to pick, I recommend GraalVM or Adoptium. You can download Adoptium from [here](https://adoptium.net/temurin/releases), and you can download GraalVM from [here](https://www.graalvm.org/downloads).
41 |
42 |
43 |
44 | # Picking the correct Java version
45 | While any Java Distributor will work just fine, you should choose the correct java version for your game version. You can check the correct version using the [Minecraft Wiki](https://minecraft.wiki). Just search your game version with "Java Edition" at the beginning and check the "Minimum Java Version".
46 |
47 | Example:
48 |
49 | 
50 |
51 |
52 |
53 | # Memory Allocation
54 | Minimum and maximum memory flags (`-xms` and `-xmx`) should be set to the same value as explained [here](https://dzone.com/articles/benefits-of-setting-initial-and-maximum-memory-siz). They are set in both megabytes or gigabytes so `-Xms4096M` and `-Xmx8G` both work.
55 |
56 |
57 | Low-Memory System where Minecraft takes up almost all your RAM
58 |
59 | Set your minimum memory below your maximum memory to conserve as much as possible. Also try removing these arguments and trying sever garbage collection arguments:
60 | - `-XX:NmethodSweepActivity=1`
61 | - `-XX:ReservedCodeCacheSize=400M`
62 | - `-XX:NonNMethodCodeHeapSize=12M`
63 | - `-XX:ProfiledCodeHeapSize=194M`
64 | - `-XX:NonProfiledCodeHeapSize=194M`
65 |
66 |
67 |
68 | > [!NOTE]
69 | > 1. Allocating too much memory can break garbage collection or just slow Minecraft down, even if you have plenty to spare. Allocating too little can also slow down or break the game. Keep a close eye on Task manager (or your DE's system monitor) as Minecraft is running, and allocate only as much as it needs (which is usually less than 8G). `sparkc gcmonitor` will tell you if your allocation is too high (the pauses will be too long) or too low (frequent GC with a low memory warning in the notification).
70 | >
71 | > 2. If you are using a third-party Minecraft launcher like Prism Launcher or ATLauncher, you shouldn't use memory arguments and instead control memory through the dedicated section in the launcher.
72 |
73 |
74 |
75 | # Base Java Flags
76 |
77 | OpenJDK
78 |
79 | ### OpenJDK 8- (Unrecommended)
80 |
81 | ```
82 | -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+ParallelRefProcEnabled -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:+PerfDisableSharedMem -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -XX:MaxInlineLevel=15 -XX:MaxVectorSize=32 -XX:+UseCompressedOops -XX:ThreadPriorityPolicy=1 -XX:+UseDynamicNumberOfGCThreads -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=350M -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:+UseFPUForSpilling
83 | ```
84 |
85 | ### OpenJDK 11+
86 |
87 | ```
88 | -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:+UseVectorCmov -XX:+PerfDisableSharedMem -XX:+UseFastUnorderedTimeStamps
89 | ```
90 |
91 | ### Extra Performance Flags (Experimental)[^1]
92 |
93 | ```
94 | -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:+EagerJVMCI -XX:+UseStringDeduplication -XX:+UseAES -XX:+UseAESIntrinsics -XX:+UseFMA -XX:+UseLoopPredicate -XX:+RangeCheckElimination -XX:+OptimizeStringConcat -XX:+UseCompressedOops -XX:+UseThreadPriorities -XX:+OmitStackTraceInFastThrow -XX:+RewriteBytecodes -XX:+RewriteFrequentPairs -XX:+UseFPUForSpilling -XX:+UseNewLongLShift -XX:+UseVectorCmov -XX:+UseXMMForArrayCopy -XX:+UseXmmI2D -XX:+UseXmmI2F -XX:+UseXmmLoadAndClearUpper -XX:+UseXmmRegToRegMoveAll -XX:+EliminateLocks -XX:+DoEscapeAnalysis -XX:+AlignVector -XX:+OptimizeFill -XX:+EnableVectorSupport -XX:+UseCharacterCompareIntrinsics -XX:+UseCopySignIntrinsic -XX:+UseVectorStubs -XX:UseAVX=2 -XX:UseSSE=4 -XX:+UseFastJNIAccessors -XX:+UseInlineCaches -XX:+SegmentedCodeCache -XX:ThreadPriorityPolicy=1
95 | ```
96 |
97 |
98 |
99 |
100 | GraalVM
101 |
102 | ### GraalVM 11- (Unrecommended)
103 |
104 | ```
105 | -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+ParallelRefProcEnabled -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -XX:+UseDynamicNumberOfGCThreads -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=350M -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:+UseFPUForSpilling -XX:+EnableJVMCI -XX:+UseJVMCICompiler -XX:+EagerJVMCI -Dgraal.TuneInlinerExploration=1 -Dgraal.CompilerConfiguration=enterprise -Dgraal.UsePriorityInlining=true -Dgraal.Vectorization=true -Dgraal.OptDuplication=true -Dgraal.DetectInvertedLoopsAsCounted=true -Dgraal.LoopInversion=true -Dgraal.VectorizeHashes=true -Dgraal.EnterprisePartialUnroll=true -Dgraal.VectorizeSIMD=true -Dgraal.StripMineNonCountedLoops=true -Dgraal.SpeculativeGuardMovement=true -Dgraal.InfeasiblePathCorrelation=true
106 | ```
107 |
108 | Though make sure to set `-Dgraal.VectorizeSIMD` to `false` if you run shaders as this version causes issues with them. This old version also breaks constellation rendering in 1.16.5 Astral Sorcery. This is possibly related to the shader bug. See: https://github.com/HellFirePvP/AstralSorcery/issues/1963
109 |
110 | ### GraalVM 17+
111 |
112 | ```
113 | -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:-DontCompileHugeMethods -XX:+PerfDisableSharedMem -XX:+UseFastUnorderedTimeStamps -XX:+EagerJVMCI -Djdk.graal.CompilerConfiguration=enterprise -Djdk.graal.TuneInlinerExploration=1
114 | ```
115 |
116 | ### Extra Performance Flags (Experimental)[^1]
117 |
118 | ```
119 | -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:+UseStringDeduplication -XX:+UseAES -XX:+UseAESIntrinsics -XX:+UseFMA -XX:+UseLoopPredicate -XX:+RangeCheckElimination -XX:+OptimizeStringConcat -XX:+UseCompressedOops -XX:+UseThreadPriorities -XX:+OmitStackTraceInFastThrow -XX:+RewriteBytecodes -XX:+RewriteFrequentPairs -XX:+UseFPUForSpilling -XX:+UseNewLongLShift -XX:+UseVectorCmov -XX:+UseXMMForArrayCopy -XX:+UseXmmI2D -XX:+UseXmmI2F -XX:+UseXmmLoadAndClearUpper -XX:+UseXmmRegToRegMoveAll -XX:+EliminateLocks -XX:+DoEscapeAnalysis -XX:+AlignVector -XX:+OptimizeFill -XX:+EnableVectorSupport -XX:+UseCharacterCompareIntrinsics -XX:+UseCopySignIntrinsic -XX:+UseVectorStubs -XX:UseAVX=2 -XX:UseSSE=4 -XX:+UseFastJNIAccessors -XX:+UseInlineCaches -XX:+SegmentedCodeCache -XX:ThreadPriorityPolicy=1
120 | ```
121 |
122 |
123 |
124 |
125 | OpenJ9
126 |
127 | ### OpenJ9 (Unrecommended)
128 |
129 | ```
130 | -XX:+IdleTuningGcOnIdle -XX:+UseAggressiveHeapShrink -XX:-OmitStackTraceInFastThrow -XX:+UseFastAccessorMethods -XX:+OptimizeStringConcat -Xshareclasses:allowClasspaths -Xshareclasses:cacheDir=./cache -Xaot -XX:+UseCompressedOops -XX:ObjectAlignmentInBytes=256 -Xshareclasses -XX:SharedCacheHardLimit=800M -Xtune:virtualized -XX:+TieredCompilation -XX:InitialTenuringThreshold=5 -Dlog4j2.formatMsgNoLookups=true -XX:-DisableExplicitGC -XX:InitiatingHeapOccupancyPercent=35 -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=6 -Djava.net.preferIPv4Stack=true -XX:-ParallelRefProcEnabled-XX:+UseTLAB -XX:ReservedCodeCacheSize=70M -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20
131 | ```
132 |
133 |
134 |
135 |
136 | Platform Prime
137 |
138 | ### Platform Prime
139 |
140 | Usually no tuning with special flags is necessary, Large Pages are still applicable though. See https://github.com/brucethemoose/Minecraft-Performance-Flags-Benchmarks/issues/49#issuecomment-1716138313.
141 |
142 |
143 |
144 | > [!NOTE]
145 | > Adding `--add-modules=jdk.incubator.vector` can help some server softwares like like Pufferfish and Purpur with explicit support for it.
146 |
147 |
148 |
149 | # Garbage Collection
150 | **Garbage collection flags should be added to Minecraft servers and clients**, as the default "pauses" to stop and collect garbage manifest as stutters on the client and lag on servers. Use the `/sparkc gcmonitor` command in Spark to observe pauses in-game. *Any* old generation pauses are bad, and young generation G1GC collections should be infrequent, but short enough to be imperceptible.
151 |
152 |
153 |
154 | ### Non-Proactive ZGC
155 | Non-Proactive ZGC is great for high memory/high core count servers. It has no server throughput hit I can measure, and absolutely does not stutter. However, it requires more RAM and more cores than other garbage collectors. Enable it with
156 | ```
157 | -XX:+UseZGC -XX:AllocatePrefetchStyle=1 -XX:-ZProactive
158 | ```
159 |
160 | > [!NOTE]
161 | > 1. It has a significant client FPS hit.
162 | >
163 | > 2. Non-Proactive ZGC is unavailable in Java 8 and much less performant in Java 11 than it is in Java 17+.
164 | >
165 | > 3. Allocate more RAM and more `ConcGCThreads` than you normally would for other GC.
166 | >
167 | > 4. GraalVM currently disables EnableJVMCI when using ZGC since it doesn't support it.
168 |
169 |
170 |
171 | ### Generational ZGC
172 | Generational ZGC is great for high memory/high core count servers and is made to be competitive with the only other Generation GC, G1GC. Enable it with
173 | ```
174 | -XX:+UseZGC -XX:AllocatePrefetchStyle=1 -XX:+ZGenerational
175 | ```
176 |
177 | > [!NOTE]
178 | > 1. Generational ZGC is only available in Java 21+
179 | >
180 | > 2. Allocate more RAM and more `ConcGCThreads` than you normally would for other GC.
181 | >
182 | > 3. GraalVM currently disables EnableJVMCI when using ZGC since it doesn't support it.
183 | >
184 | > 4. Java 23+ no longer requires `-XX:+ZGenerational` flag. Remove it if you want as it will just be ignored since Generational is the new default.
185 |
186 |
187 |
188 | ### Shenandoah
189 | Shenandoah performs well on clients, but kills server throughput. Enable it with
190 | ```
191 | -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGuaranteedGCInterval=1000000 -XX:AllocatePrefetchStyle=1
192 | ```
193 |
194 | See more tuning options [here](https://wiki.openjdk.org/display/shenandoah/Main). The "herustic" and "mode" options don't change much (except for "compact," which you should not use).
195 |
196 | > [!NOTE]
197 | > 1. Red Hat OpenJDK 8 is the only Java 8 JDK that supports Shenandoah.
198 | >
199 | > 2. GraalVM currently doesn't support Shenandoah.
200 |
201 |
202 |
203 | ### Client G1GC
204 | G1GC is the default garbage collector for all JREs. Aikar's [famous Minecraft server G1GC arguments](https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/) run great on clients, with two caveats: they effectively [clamp](https://www.oracle.com/technical-resources/articles/java/g1gc.html) the `MaxGCPauseMillis` parameter by setting `G1NewSizePercent` so high, producing long stutters on some clients, and they collect oldgen garbage too aggressively (as the client produces *far* less than a populated server).
205 |
206 | These are similar to the Aikar flags, but with shorter, more frequent pauses, less aggressive G1 mixed collection and more aggressive background collection:
207 | ```
208 | -XX:+UseG1GC -XX:MaxGCPauseMillis=37 -XX:+PerfDisableSharedMem -XX:G1HeapRegionSize=16M -XX:G1NewSizePercent=23 -XX:G1ReservePercent=20 -XX:SurvivorRatio=32 -XX:G1MixedGCCountTarget=3 -XX:G1HeapWastePercent=20 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1RSetUpdatingPauseTimePercent=0 -XX:MaxTenuringThreshold=1 -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5.0 -XX:GCTimeRatio=99 -XX:G1ConcRefinementServiceIntervalMillis=150 -XX:G1ConcRSHotCardLimit=16 -XX:AllocatePrefetchStyle=3
209 | ```
210 |
211 | > [!NOTE]
212 | > 1. Java 21+ no longer supports `-XX:G1ConcRefinementServiceIntervalMillis=150` flag and the `-XX:G1ConcRSHotCardLimit=16` flag. Remove them if you want as they will just be ignored.
213 | >
214 | > 2. `G1NewSizePercent` and `MaxGCPauseMillis` can be used to tune the frequency/dureation of your young generation collections. `G1HeapWastePercent=18` should be removed if you are getting any old generation pauses on your setup. Alternatively, you can raise it and set `G1MixedGCCountTarget` to 2 or 1 to make mixed garbage collection even lazier (at the cost of higher memory usage).
215 | >
216 | > 3. If you are using a Java 8 based GraalVM EE, change `-XX:AllocatePrefetchStyle=3` to `-XX:AllocatePrefetchStyle=1`
217 |
218 |
219 |
220 | ### Server G1GC
221 | Longer pauses are more acceptable on servers. These flags are very close to the aikar defaults:
222 |
223 | ```
224 | -XX:+UseG1GC -XX:MaxGCPauseMillis=130 -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=28 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=20 -XX:G1MixedGCCountTarget=3 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=0 -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=1 -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5.0 -XX:G1ConcRefinementServiceIntervalMillis=150 -XX:G1ConcRSHotCardLimit=16 -XX:AllocatePrefetchStyle=3
225 | ```
226 |
227 | > [!NOTE]
228 | > 1. Java 21+ no longer supports `-XX:G1ConcRefinementServiceIntervalMillis=150` flag and the `-XX:G1ConcRSHotCardLimit=16` flag. Remove them if you want as they will just be ignored.
229 | >
230 | > 2. `G1NewSizePercent` and `MaxGCPauseMillis` can be used to tune the frequency/dureation of your young generation collections. `G1HeapWastePercent=18` should be removed if you are getting any old generation pauses on your setup. Alternatively, you can raise it and set `G1MixedGCCountTarget` to 2 or 1 to make mixed garbage collection even lazier (at the cost of higher memory usage).
231 | >
232 | > 3. If you are using a Java 8 based GraalVM EE, change `-XX:AllocatePrefetchStyle=3` to `-XX:AllocatePrefetchStyle=1`
233 |
234 |
235 |
236 | ### Garbage Collection Threading
237 | `-XX:ConcGCThreads=[Some Number]` controls the [*maximum* number](https://github.com/openjdk/jdk/blob/dd34a4c28da73c798e021c7473ac57ead56c9903/src/hotspot/share/gc/z/zHeuristics.cpp#L96-L104) of background threads the garbage collector is allowed to use, and defaults to `[number of logical (hyperthreaded) cores / 4]`. Recent versions of Java will [reduce the number of gc threads, if needed](https://wiki.openjdk.org/display/zgc/Main#Main-SettingConcurrentGCThreads).
238 |
239 | In some cases (especially with ZGC or Shenandoah) you want to increase this thread cap past the default. I recommend `[number of REAL (non-hyperthreaded) cores - 2]` on most CPUs, but you may need to play with this parameter. If its too low, garbage collection can't keep up with Minecraft, and the game will stutter and/or start eating gobs of RAM and crash. If its too high, it might slow the game down, especially if you are running Java 8. Probably keep it under 8 (you can maybe get away with 10 for ZGC and Shenandoah).
240 |
241 | No other "threading" flags like `ParallelGCThreads` or `JVMCIThreads` are necessary, as they are enabled by default with good automatic settings in Java 8+.
242 |
243 |
244 |
245 | # Large Pages
246 |
247 | > [!CAUTION]
248 | > Some guides say that you must run Java and your launcher as administrator on Windows. This has been shown wrong and is a MAJOR SECURITY RISK.
249 |
250 | > [!NOTE]
251 | > If you allocate more than 8 GB of memory to Minecraft, Java may crash on Windows. More details in this issue: https://github.com/adoptium/adoptium-support/issues/626
252 | > You can try running `enable-mmagent -pagecombining` in a admin terminal to fix it.
253 |
254 | Enabling large pages improves the performance of Minecraft servers and clients by reducing the load on your system. [Here's a good guide](https://kstefanj.github.io/2021/05/19/large-pages-and-java.html)
255 |
256 | Add:
257 | ```
258 | -XX:+UseLargePages -XX:LargePageSizeInBytes=2m
259 | ```
260 |
261 | Check and see if large pages is working with the `-Xlog:gc+init` java argument in Java 17.
262 |
263 | In any Java version/platform, if large pages isn't working, you will get a warning in the log similar to this:
264 |
265 | ```
266 | Java HotSpot(TM) 64-Bit Server VM warning: JVM cannot use large page memory because it does not have enough privilege to lock pages in memory.
267 | ```
268 |
269 | > [!NOTE]
270 | > 1. Windows Home doesn't have `gpedit.msc` and thus, can't follow the guide above, intead use [this guide](https://awesomeprojectsxyz.blogspot.com/2017/11/windows-10-home-how-to-enable-lock.html?m=1), also since microsoft took down the tool in mention, you have to download it from [here](https://gist.github.com/eyecatchup/0107bab3d92473cb8a3d3547848fc442).
271 | >
272 | > 2. On Linux, you generally want to use `-XX:+UseTransparentHugePages`.
273 |
274 |
275 |
276 | # SpecialK
277 | A "universal" Windows mod akin to [ReShade](https://reshade.me/), SpecialK has 2 major performance benefits:
278 |
279 | - A "smart" frame limiter that reduces stutter, eliminates tearing, saves power, and saves CPU TDP to boost when needed. It even works in conjuction with VRR or Nvidia Reflex.
280 |
281 | - A OpenGL-to-DirectX11 wrapper called OpenGL-IK that eliminates Minecraft's windowed mode overhead, and enables other features (like auto-HDR or a resizable borderless window).
282 |
283 | Download it [here](https://www.special-k.info/).
284 |
285 | Add your Minecraft launcher. Then navigate to your java bin folder where your javaw.exe is, and create an empty file called `SpecialK.OpenGL32`. Launch your Minecraft launcher with the SpecialK launcher, and the launcher will then "inject" SpecialK into Minecraft.
286 | 
287 |
288 | You can create a desktop shortcut to your Minecraft launcher through the SpecialK UI for even more convenience.
289 |
290 | Be sure to turn off VSync and the in-game Minecraft frame limiter.
291 |
292 |
293 |
294 | # Process Priority
295 | After launching Minecraft, set Java to run at an "Realtime" process priority in Windows with the Task Manager in the details tab:
296 |
297 | 
298 |
299 | Linux users can add `sudo nice -n -10` to the beginning of the launch command.
300 |
301 | > [!CAUTION]
302 | > On Linux, nice levels below 0 (with the "max" being -20) require running nice as `root` which in turn runs Minecraft as `root`. This is a security risk. Here are some Workarounds:
303 | > 1. Start game and run `renice -10 -p $(PID)` as `root` instead with the pid of the minecraft instance. This is safe as Minecraft itself is not running as `root`.
304 | >
305 | > 2. Modify `/etc/security/limits.conf` to allow non-root users to go to negatives. Then just use the normal nice command without `sudo`. Don't do this one if you don't know what you are doing.
306 | >
307 | > 3. "Hacky" way to script it: `sudo nice -n -10 su -c`. The easiest way but the first 2 are probably better.
308 |
309 |
310 |
311 | # Other Performance Tips
312 | - Run Minecraft on Linux! In pretty much every scenario it runs very good, for servers, Clear Linux and RHEL are very well optimized, and for clients, CachyOS/Arch is amazing.
313 |
314 | - Make sure the Minecraft client is using your discrete GPU! Check the F3 tab, and force Minecraft to use it in the "**Windows Graphics Settings**", *not* the AMD/Nvidia control panel (as they don't seem to work anymore).
315 |
316 | - Linux wayland users should research running Minecraft natively on wayland instead of through xwayland.
317 |
318 | - Close everything in the background, including Discord, game launchers and your browser! Minecraft is resource intensive, and does not like other apps generating CPU interrupts or eating disk I/O, RAM and so on.
319 |
320 |
321 |
322 | [^1]: https://github.com/MeowIce/meowice-flags
323 |
--------------------------------------------------------------------------------
/javaVersion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mukul1127/Minecraft-Java-Flags/d83ddc5540e1b1eff00f0303c41526481e439f77/javaVersion.png
--------------------------------------------------------------------------------
/specialk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mukul1127/Minecraft-Java-Flags/d83ddc5540e1b1eff00f0303c41526481e439f77/specialk.png
--------------------------------------------------------------------------------
/taskmgr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mukul1127/Minecraft-Java-Flags/d83ddc5540e1b1eff00f0303c41526481e439f77/taskmgr.png
--------------------------------------------------------------------------------