English
Minecraft JVM Arguments & Best GC Settings
Minecraft (Java Edition) is a JVM application — every tick of your world runs on the Java Virtual Machine, and the #1 cause of server lag spikes is garbage collection. Choosing the right JVM arguments can be the difference between a smooth 20 TPS and constant rubber-banding.
Why the default settings hurt
The vanilla launcher and many server hosts start the JVM with modest heap sizes and, historically, no explicit collector. Minecraft allocates a lot of short-lived objects (block updates, entities, packets). With a small heap:
- The young generation fills up every few seconds → frequent GC pauses.
- Every pause = the server freezes = players see lag spikes.
- On modded servers, thousands of classes also stress the metaspace.
How much RAM? (-Xmx / -Xms)
Give the JVM enough heap, and set initial = max so it never resizes mid-game:
| Setup | Recommended -Xmx |
|---|---|
| Vanilla client, normal render distance | 2–4 GB |
| Modded client (light–medium modpack) | 4–6 GB |
| Vanilla server (10 players) | 4–8 GB |
| Modded server (100+ mods) | 6–12 GB |
-Xms4G -Xmx4GMore RAM is not always better
An oversized heap makes each Full GC sweep much more memory → longer pauses. Give the JVM what it needs, not everything you have.
Use a modern garbage collector
The single most impactful argument: replace the default collector with G1GC tuned for Minecraft's allocation pattern. The community-standard approach (popularized as "Aikar's flags" for Paper servers) follows these principles:
- G1GC with a small pause goal — pauses of a few ms instead of hundreds.
- Larger young generation (
-XX:G1NewSizePercent=40) — Minecraft's objects die extremely young; a bigger Eden means fewer collections. - Aggressive mixed collection (
-XX:MaxGCPauseMillis=130, raised initiating occupancy) — reclaim old space before a Full GC is forced. - Metaspace headroom for modded setups (
-XX:MaxMetaspaceSize=256M).
A minimal modern starting point for a server:
bash
java -Xms4G -Xmx4G \
-XX:+UseG1GC -XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 \
-XX:MaxGCPauseMillis=130 -XX:InitiatingHeapOccupancyPercent=30 \
-XX:MaxMetaspaceSize=256M -jar server.jar noguiPaper/Purpur servers ship with sensible defaults built in — but the GC settings above still apply when you tune further.
Then measure, don't guess
Add GC logging to your startup (one line), let the server run through a normal session, and look at the actual pauses:
bash
# add to the startup command (Java 9+)
-Xlog:gc*:file=gc.log:time,uptimeThen drop gc.log into the GC Log Analyzer: you will see exactly how long each pause is, how often they happen, and whether the heap is big enough. If the report shows frequent long pauses or a climbing after-GC line, raise -Xmx or apply the G1 flags above — then re-analyze to confirm.
Typical result
A modded server we tested went from 8-15 s of GC time per minute with default settings to sub-second total GC per minute with G1 + right-sized heap — lag spikes gone.
Related pages
- Java GC Collectors Compared — why G1/ZGC suit Minecraft
- JVM Performance Tuning Guide — the full tuning workflow
- Enable GC Logging — flags for older Java versions