Aikar's Flags: The Ultimate Minecraft Lag Fix Guide (Java 21+ Servers)
Eliminate GC lag spikes on your Minecraft server using tuned Aikar's Flags. A complete setup guide for Java 21+ performance optimization.
Reading time: 2 min read
Why Aikar's Flags are Essential for Java 21+ Servers
If you've ever seen your Minecraft server's TPS drop for a split second every minute, you're likely experiencing "GC Lag Spikes." While Java 21 (required for modern Minecraft) is incredibly efficient, it still needs to be tuned for the specific, "bursty" memory usage patterns of a Minecraft server.
What are Aikar's Flags?
Aikar's Flags are a set of optimized Java Virtual Machine (JVM) startup parameters specifically tuned for Minecraft servers. They focus on the G1 Garbage Collector (G1GC), which is designed to handle large heaps with very low latency.
Why Do You Need Them?
By default, Java's garbage collector is designed for general-purpose applications. It might wait too long to clean up RAM, resulting in a massive, time-consuming "Stop the World" event that freezes your server.
Aikar's Flags change this behavior to:
- Incremental Cleaning: Collecting small amounts of "garbage" memory constantly rather than doing one big cleanup.
- Improved Parallelism: Utilizing more CPU threads to handle memory management off the main game thread.
- Reference Processing: Speeding up the way Java handles "soft" and "weak" references, which Minecraft uses heavily for world data.
How to Apply Them
You shouldn't just copy random flags from the internet. The best practice is to use a generator like flags.sh. This tool will provide you with a customized startup script based on your server's RAM and CPU profile.
Example for Java 21 Servers (8GB+ RAM):
java -Xms8G -Xmx8G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar server.jar noguiKey Flags Explained
-Xmsand-Xmx: must be the same value. This prevents the server from constantly resizing the heap, which causes lag.-XX:+AlwaysPreTouch: This forces Java to "touch" every page of RAM at startup. This makes startup slower but prevents the OS from having to find new RAM pages during gameplay.-XX:MaxGCPauseMillis=200: This tells Java to aim for a maximum pause time of 200ms, which is roughly the threshold for a noticeable lag spike.
Conclusion
Tuning your JVM is one of the easiest ways to gain free performance. If you aren't using Aikar's Flags, you're leaving performance on the table and subjecting your players to unnecessary lag spikes.
Related posts
How to Allocate More RAM to Minecraft
If your Minecraft is stuttering or crashing, it might be running out of memory. Learn how to allocate more RAM in the Java Edition launcher.
Minecraft Java vs. Bedrock: Which Edition is Better in 2026?
A professional comparison of the two main versions of Minecraft. We look at performance, mods, cross-play, and PvP mechanics.
Top 5 Minecraft Performance Mods for 1.21.1 (Sodium & More)
If your Minecraft Java Edition is lagging, you need these mods. Learn how Sodium, Lithium, and Iris can triple your FPS instantly.
