Skip to content

About

List of JVM arguments and mods to optimize minecraft.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

minecraft-optimization

JVM Flags

JVM launch flags for low-latency garbage collection and stable memory behavior.

Flag Purpose Supported on
-Xms{memory}M Sets the minimum and the initial size (in bytes) of the heap. HotSpot JVM
-Xmx{memory}M Specifies the maximum size (in bytes) of the heap. For server deployments, -Xms and -Xmx are often set to the same value. HotSpot JVM
-XX:+UseZGC Enables the use of the Z garbage collector (ZGC). This is a low latency garbage collector, providing max pause times of a few milliseconds, at some throughput cost. Pause times are independent of what heap size is used. Supports heap sizes from 8MB to 16TB. Production since JDK 15 (experimental since JDK 11)
-XX:+UseStringDeduplication Enables string deduplication: identical String objects point to and share the same character array, reducing the memory footprint of String objects on the Java heap. G1 (Oracle's man page requires it); ZGC since JDK 18
-XX:+UseCompactObjectHeaders Enables compact object headers, reducing the size of every object header in the Java heap from 96 or 128 bits to 64 bits and the heap footprint by 4 bytes per object (on average); often improves performance. Limited to 4 million loaded classes. JDK 24 experimental (needs -XX:+UnlockExperimentalVMOptions); product since JDK 25
-XX:+AlwaysPreTouch Requests the VM to touch every page on the Java heap after requesting it from the operating system and before handing memory out to the application. HotSpot JVM
-XX:TrimNativeHeapInterval=5000 Interval, in ms, at which the JVM will trim the native heap. Lower values will reclaim memory more eagerly at the cost of higher overhead. A value of 0 (default) disables native heap trimming. Linux with glibc only
-XX:+UseTransparentHugePages Linux only: enables the use of large pages that can dynamically grow or shrink. With ZGC this is the alternative to explicit large pages and must be combined with -XX:+UseLargePages. Linux only; with ZGC needs kernel 4.7+

Requirements

  • JDK 25+ recommended. Only -XX:+UseCompactObjectHeaders needs it: experimental in JDK 24 (add -XX:+UnlockExperimentalVMOptions), product since JDK 25. Everything else here runs on JDK 21.

  • -XX:+ZGenerational. Needed on JDK 21 to 23 to opt into generational ZGC. ZGC is generational by default since JDK 23 and the non-generational mode was removed in JDK 24, so drop the flag on JDK 24+ (JEP 439/474/490).

  • -XX:-ZUncommit. Disables ZGC returning unused memory to the OS. This guide runs -Xms equal to -Xmx, so ZGC never shrinks below -Xms and uncommit cannot happen: the flag is unnecessary. Add it only if you set -Xms below -Xmx and want the memory kept resident.

  • Transparent huge pages. The JVM also needs -XX:+UseLargePages. Check whether they are already enabled:

    cat /sys/kernel/mm/transparent_hugepage/enabled
    cat /sys/kernel/mm/transparent_hugepage/shmem_enabled

    ZGC needs [madvise] in the first and [advise] in the second. If they are not selected, enable them (they do not persist across reboots):

    echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
    echo advise  | sudo tee /sys/kernel/mm/transparent_hugepage/shmem_enabled

    With the common always + shmem_enabled=never default, every GC except ZGC still gets huge pages, but ZGC does not.

Usage

Add the flags to the launch command:

java -Xms4096M -Xmx4096M \
  -XX:+UseZGC \
  -XX:+UseStringDeduplication \
  -XX:+UseCompactObjectHeaders \
  -XX:+AlwaysPreTouch \
  -XX:TrimNativeHeapInterval=5000 \
  -XX:+UseLargePages \
  -XX:+UseTransparentHugePages \
  -jar server.jar nogui

On JDK 24 add -XX:+UnlockExperimentalVMOptions if you keep -XX:+UseCompactObjectHeaders; from JDK 25 on it is a product flag.

Memory trade-off

Setting -Xms equal to -Xmx disables ZGC uncommit (it never releases memory below -Xms), and with AlwaysPreTouch the whole heap is committed at startup: consistent latency for fixed RAM.

Raising {memory} above the default is recommended, and a larger heap has few downsides for ZGC beyond the extra resident RAM and a slightly slower first startup.

Oracle's tuning strategy: "Set the maximum heap size to a value that's close to the total physical memory on the platform, but doesn't cause swapping of the application."

Because the pre-touched heap plus the JVM's native overhead (roughly 1 GiB, outside {memory}) is resident from the first second, "close" still means leaving enough for the OS and that overhead. Tune by watching the used heap (jcmd <pid> GC.heap_info, or the GC logs).

Mods

Ordered by side. Both means it works single-sided on either server or client side; Server and Client are single-side.

Mod Purpose Side
C2ME A Fabric mod designed to improve the chunk performance of Minecraft. Both
FerriteCore Memory usage optimizations Both
FoamFix FoamFix is a mod designed to improve modded Minecraft memory usage using simple, targeted optimizations. Both
Krypton A mod to optimize the Minecraft networking stack Both
Lithium No-compromises game logic optimization mod, useful for both single-player games and multi-player servers. Both
Memory Leak Fix A mod that fixes random memory leaks for both the client and server Both
ModernFix All-in-one mod that improves performance, reduces memory usage, and fixes many bugs. Compatible with all your favorite performance mods! Both
Packet Fixer A simple mod to fix various problems with packets, nbt and timeouts. Both
Redirected Memory optimization mod that prevents duplication of Enum values. Both
ScalableLux A Fabric mod based on Starlight that improves the performance of light updates in Minecraft. Both
ThreadTweak Improve and tweak Minecraft thread scheduling. Fork of Smooth Boot for ≥1.20 Both
Very Many Players A Fabric mod designed to improve server performance at high playercounts. Both
Voxy Server Side Render distant Voxy LODs on servers Both
Voxy WorldGen This is a passive chunk generator mod, with server-side support for Voxy! Both
XXL Packets XXL Packets is a fork of XL Packets which raises the packet size limit from 2MB to the Java Integer limit (2.147483647 GB). Both
Alternate Current An efficient and non-locational redstone dust implementation Server
C2ME OpenCL Acceleration Module C2ME addon that provides hardware accelerated world generation through OpenCL Server
Cerulean Advancements optimization mod, updated fork of Icterine with added features Server
Clumps Clumps XP orbs together to reduce lag Server
RailOptimization A simple mod that makes powered/activator rails turn on/off up to 12x faster. Server
Despawn Tweaks Optimization mod that fixes cases where mobs will be prevented from despawning. Server
Fast Noise Vanilla Worldgen optimization mod Server
Immersive Optimization A lightweight entity-tick-scheduler for doubling your TPS. Server
Ksyxis Speed up your world loading by removing unneeded chunks. Server
ServerCore A mod that aims to optimize the minecraft server. Server
BadOptimizations Optimization mod that focuses on things other than rendering Client
Enhanced Block Entities Reduce block entity FPS lag with almost no compromises, and improve their visuals Client
Entity Culling Using async path-tracing to hide Block-/Entities that are not visible Client
FastAnim Speeds up entity animation calculations! Client
FeyTweaks Mod for optimizing signs and beacons. Client
Flerovium Greatly improve your fps with virtually no side-effects on graphics quality Client
GPUBooster Provides DSA & fastest math formulas to game render system for best perfomance! Compatible with Sodium/Embeddium, Iris and shaders. Client
ImmediatelyFast Speed up immediate mode rendering in Minecraft Client
Ixeris Buffered raw input and threaded event polling Client
More Culling A mod that changes how multiple types of culling are handled in order to improve performance Client
Nvidium Fast nvidia only rendering engine for sodium Client
Particle Core Particle optimizations: Culling, rendering optimizations, configurable particle-type-specific spawn reduction, and potion particle disabling. Compatible with Sodium, improves performance over Sodium alone. Client
Sodium A high-performance rendering engine replacement for Minecraft, which greatly improves frame rates and reduces micro-stutter. Client
Stfu A mod that fixes some annoyances and speeds up your game! Client
voxy A Level of Detail rendering mod Client

Server

Software

Pumpkin: Written in Rust; fast, but in active development and not yet feature-complete.

Paper: High-performance fork of Spigot that fixes gameplay and mechanics inconsistencies; the de facto standard for plugin servers.

Folia: Fork of Paper that runs the game loop across multiple threads; breaks compatibility with many plugins.

Paper & Forks Optimization

YouHaveTrouble/minecraft-optimization: community optimization guide for Paper servers and their forks (Purpur, Pufferfish, Leaf and others).

Sources

About

List of JVM arguments and mods to optimize minecraft.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors