Back to Blog
jvmgarbage collectionlag spikespaperperformancejavaaikar flagsg1gc

Minecraft Server Garbage Collection Tuning: Stop JVM Lag Spikes for Good

Published on July 04, 2026

# Minecraft Server Garbage Collection Tuning: Stop JVM Lag Spikes for Good

Your server runs at a smooth 20 TPS for minutes, then suddenly drops to 12 TPS for a second or two — and nobody did anything obvious to cause it. If this sounds familiar, Java garbage collection (GC) is almost certainly the culprit. This is one of the most misunderstood sources of Minecraft server lag, and fixing it can dramatically improve the experience for your players.

In this guide, we'll explain what garbage collection is, why it causes lag spikes, and exactly which JVM flags to use to minimize the problem.

What Is Garbage Collection and Why Does It Cause Lag?

Minecraft (and its server software) runs on the Java Virtual Machine (JVM). Java manages memory automatically — when objects are no longer needed (old chunks, despawned entities, expired timers), the JVM's garbage collector reclaims that memory.

The problem: during a GC pause, the JVM briefly stops all application threads. For a Minecraft server, this means the entire tick loop freezes. Even a 200ms GC pause translates directly into a visible lag spike for every player online.

By default, Java doesn't use settings optimized for Minecraft's memory usage patterns. Tuning the garbage collector is one of the highest-impact optimizations you can make — and it requires zero changes to your plugins or config files.

The Best JVM Flags for Minecraft Servers (Aikar's Flags)

The gold standard for Minecraft server JVM tuning is Aikar's Flags — a set of G1GC parameters developed specifically for Minecraft's heap behavior. These are widely recommended by Paper, Purpur, and most major server networks.

Here are the flags for servers with 12GB or more of RAM allocated:

java -Xms12G -Xmx12G \

-XX:+UseG1GC \

-XX:+ParallelRefProcEnabled \

-XX:MaxGCPauseMillis=200 \

-XX:+UnlockExperimentalVMOptions \

-XX:+DisableExplicitGC \

-XX:+AlwaysPreTouch \

-XX:G1NewSizePercent=30 \

-XX:G1MaxNewSizePercent=40 \

-XX:G1HeapRegionSize=8M \

-XX:G1ReservePercent=20 \

-XX:G1HeapWastePercent=5 \

-XX:G1MixedGCCountTarget=4 \

-XX:InitiatingHeapOccupancyPercent=15 \

-XX:G1MixedGCLiveThresholdPercent=90 \

-XX:G1RSetUpdatingPauseTimePercent=5 \

-XX:SurvivorRatio=32 \

-XX:+PerfDisableSharedMem \

-XX:MaxTenuringThreshold=1 \

-Dusing.aikars.flags=https://mcflags.emc.gs \

-jar paper.jar --nogui

For servers with less than 12GB RAM, adjust these two values:

-XX:G1NewSizePercent=20

-XX:G1MaxNewSizePercent=30

Why These Settings Work

  • -XX:+UseG1GC — Switches to the Garbage-First collector, which is designed to keep pause times short and predictable rather than maximizing throughput.
  • -XX:MaxGCPauseMillis=200 — Tells G1GC to target pauses under 200ms. It won't always succeed, but this guides the collector's behavior.
  • -XX:InitiatingHeapOccupancyPercent=15 — Starts GC cycles earlier (at 15% heap occupancy) instead of waiting until the heap is nearly full. This prevents massive stop-the-world collections.
  • -XX:AlwaysPreTouch — Allocates all RAM upfront at startup instead of on demand. This prevents OS-level memory allocation delays during gameplay.
  • -XX:+DisableExplicitGC — Prevents plugins from calling System.gc() manually, which can trigger full GC pauses at the worst possible moments.
  • -Xms equals -Xmx — Setting minimum and maximum heap to the same value prevents the JVM from resizing the heap at runtime, which causes its own pauses.

Should You Use ZGC or Shenandoah Instead?

Newer low-latency garbage collectors like ZGC (Java 15+) and Shenandoah (Java 11+) aim for sub-millisecond pauses by doing most work concurrently.

For Minecraft servers, the verdict is mixed:

  • ZGC works well on servers with very large heaps (32GB+) or very high player counts where G1GC still struggles. Use -XX:+UseZGC and drop the other G1-specific flags.
  • Shenandoah shows similar characteristics but is only available in OpenJDK builds, not Oracle JDK.
  • G1GC with Aikar's flags remains the best choice for most servers in the 4–16GB range.

If you want to experiment with ZGC, a minimal startup line looks like:

java -Xms10G -Xmx10G -XX:+UseZGC -XX:+AlwaysPreTouch -jar paper.jar --nogui

Choosing the Right Java Version

Always run your Minecraft server on Java 21 (LTS). Each major Java release brings GC improvements:

  • Java 21 significantly improved G1GC pause times compared to Java 11 or 17
  • Java 21 includes virtual threads (Project Loom), which Folia and future Paper builds leverage
  • Avoid Java 8 entirely for modern Paper/Purpur servers — GC behavior is far worse

Check your current version with:

java -version

Monitoring GC Pauses in Practice

Tuning without data is guesswork. Add these flags to enable GC logging:

-Xlog:gc*:logs/gc.log:time,uptime:filecount=5,filesize=10m

This creates rotating GC logs in your logs/ folder. Look for lines showing pause times above 100ms — those are your problem collections.

For ongoing monitoring, tools like [PulseNode](https://pulsenode.tech) track your server's TPS and performance over time, making it easy to correlate GC-related lag spikes with real player impact rather than digging through raw log files.

Common Mistakes to Avoid

  • Allocating too much RAM — Counterintuitively, giving your server 32GB when it only needs 8GB makes GC worse. Larger heaps mean more objects to scan. Start with 6–10GB and increase only if heap usage consistently exceeds 80%.
  • Using -XX:+UseConcMarkSweepGC — This collector is deprecated and removed in Java 14+. Never use it.
  • Mismatched -Xms and -Xmx — Always keep them equal to avoid heap resizing pauses.
  • Running multiple servers on one JVM — Each server instance should have its own JVM process with its own memory allocation.

Quick Checklist

  • [ ] Use Java 21 LTS
  • [ ] Apply Aikar's Flags with matched -Xms and -Xmx
  • [ ] Don't over-allocate RAM (stay under 16GB unless needed)
  • [ ] Enable GC logging to verify improvements
  • [ ] Monitor TPS stability after changes

Wrapping Up

Garbage collection tuning is one of those optimizations that feels invisible when it's working correctly — your server just stays smooth without mysterious lag spikes. Applying Aikar's Flags takes less than five minutes and can eliminate the most frustrating type of Minecraft server lag entirely.

Once you've updated your startup flags, use [PulseNode](https://pulsenode.tech) to monitor your TPS over the following days and confirm the spikes are gone. If they're not, the GC logs will tell you exactly where to look next.

Optimize your server performance?

PulseNode monitors your Minecraft server in real-time and gives you AI-powered optimization tips.

Start for free
Minecraft Server Garbage Collection Tuning: Stop JVM Lag Spikes for Good — PulseNode Blog | PulseNode