Skip to content
Preptima
hardScenarioDesignSeniorStaff

How do you optimise Java Virtual Machine (JVM) garbage collection to eliminate tail latency spikes in a game server?

3 min readUpdated 2026-08-15

Answer

Short answer

Analyse JVM tuning strategies to prevent Stop-The-World (STW) pauses and ensure predictable microsecond response times for game server logic.

Game servers executing a main physics and logic loop at a strict 60Hz have a computational budget of approximately 16.6 milliseconds per tick. While the average tick execution time might be healthy, tail latency spikes at the 99.9th percentile can easily exceed 150 milliseconds due to the Java Virtual Machine (JVM) Garbage Collector (GC). These spikes cause catastrophic Stop-The-World (STW) pauses that result in rubber-banding, broken simulation determinism, and disconnected players.

The mechanics of JVM memory management dictate that rapid creation of short-lived objects (such as temporary vectors for physics calculations or byte buffers for network transmission) aggressively fills the Thread Local Allocation Buffer (TLAB) within the Young Generation. When Eden fills up, a Minor GC triggers, pausing application threads to copy survivors. If the allocation rate outpaces collection, objects are prematurely promoted to the Old Generation, eventually forcing a massive Major GC that halts the server entirely.

Was this answer helpful?

Likely follow-ups

  • How would you distinguish, from GC logs alone, whether a tail latency spike was caused by a Minor GC, a Major GC, or a Time-To-Safepoint delay?
  • If switching to ZGC still leaves occasional multi-millisecond pauses, what would you check next about the physics loop's own code before blaming the collector?
  • An engineer proposes disabling escape analysis optimisations to simplify debugging. What allocation-rate consequences would you expect on the next deploy?

Related questions