Your Minecraft server lags despite having enough RAM? The problem is almost never the memory – it's the Java configuration.
In this guide, we'll show you the most important performance optimizations: From the legendary Aikar Flags to world pre-generation with Chunky.
Found a server, but which VPS?
Use our comparison to find the perfect VPS for your player count.
Compare VPS ServersWhy Java Flags Matter
Minecraft runs on the Java Virtual Machine (JVM). Without tuning, Java regularly pauses for "Garbage Collection" – cleaning up unused data in memory.
You feel these pauses as lag spikes, even though TPS shows 20. The server freezes briefly, players rubber-band, and redstone circuits break.
Note: Default Java settings are optimized for desktop applications, not game servers with constant memory throughput.
Aikar Flags: The Gold Standard
The Aikar Flags are a collection of JVM parameters specifically developed for Minecraft servers. They optimize the G1 Garbage Collector for minimal pauses.
Here are the complete flags for servers with 8-12GB RAM:
java -Xms8G -Xmx8G \
-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 \
-jar server.jar nogui
Important: Set
-Xmsand-Xmxto the same value! Different values lead to constant heap resizing and more lag.
What Do the Key Flags Do?
The following table explains the most critical parameters:
| Flag | Function | Why It Matters |
|---|---|---|
-Xms / -Xmx | Min/Max heap size | Same values prevent resizing |
-XX:+UseG1GC | Garbage collector type | G1 is optimal for Minecraft |
-XX:+AlwaysPreTouch | Reserve RAM at startup | Prevents lag on first chunk load |
-XX:MaxGCPauseMillis=200 | Max pause time | Keeps GC pauses under 200ms |
GenZGC: For Large Modpacks (12GB+)
Starting with Java 21, there's Generational ZGC – a garbage collector that reduces pause times to under 1ms. Ideal for heavy modded servers with 12-32GB RAM.
java -Xms16G -Xmx16G \
-XX:+UseZGC \
-XX:+ZGenerational \
-XX:+AlwaysPreTouch \
-XX:+DisableExplicitGC \
-jar server.jar nogui
Tip: GenZGC requires slightly more CPU baseline load but virtually eliminates all GC lag spikes. Perfect for ATM9, Create, or other RAM-hungry modpacks.
Which Java Version?
The right Java version is crucial for performance and compatibility. Here's an overview:
| Minecraft Version | Java Version | Note |
|---|---|---|
| 1.17 - 1.17.1 | Java 16+ | Minimum |
| 1.18 - 1.20.4 | Java 17 | LTS, recommended |
| 1.20.5+ | Java 21 | Required, new features |
| 1.21+ | Java 21 (or 23) | Java 23 experimental |
Tip: Always use the LTS version (17 or 21). Java 23 brings performance improvements but isn't officially supported by Forge yet.
Pre-Generate World with Chunky
The biggest lag source: Generating new chunks while players explore. Every new chunk means complex terrain calculation in real-time.
The solution: Generate the world before players join with the Chunky plugin.
/chunky radius 5000
/chunky start
# Wait until complete (can take hours)
/chunky confirm
How Long Does It Take?
Generation time depends on radius and CPU:
| Radius | World Size | Generation Time |
|---|---|---|
| 5,000 blocks | ~4GB | 2-4 hours |
| 10,000 blocks | ~17GB | 12-24 hours |
Note: After pre-generation, the server only needs to load chunks from SSD – instead of calculating them live. This saves 50-80% CPU load during gameplay.
View Distance vs. Simulation Distance
View distance determines how many chunks are loaded per player. The formula: (2d + 1)² chunks per player.
This means: Small changes have massive impact:
| View Distance | Chunks per Player | Assessment |
|---|---|---|
| 6 | 169 | Minimal, but playable |
| 8 | 289 | Standard for budget servers |
| 10 | 441 | Vanilla default |
| 12 | 625 | Only for powerful CPUs |
| 16 | 1089 | Not recommended for MP |
Pro tip: Set
view-distanceto 10 (visuals), butsimulation-distanceto 5 (calculations). Players see far, but mobs and redstone are only calculated nearby. Saves 50%+ CPU!
Quick Optimizations (5 Minutes)
These changes in server.properties and spigot.yml bring immediate performance gains:
| Setting | Effect |
|---|---|
view-distance=8 | 30% less chunk loading |
simulation-distance=5 | 50% less entity ticking |
network-compression-threshold=256 | Less network overhead |
max-tick-time=-1 | Prevents watchdog crashes during lag |
Frequently Asked Questions
Conclusion
The most important optimizations at a glance:
- Use Aikar Flags – for servers up to 12GB RAM
- Enable GenZGC – for modpacks with 12GB+ RAM
- Pre-generate world – shift CPU load with Chunky
- Separate View/Simulation Distance – high visuals, low calculations
More Minecraft Guides
Found a server, but which VPS?
Use our comparison to find the perfect VPS for your player count.
Compare VPS Servers

