Top 3 JVM Garbage Collectors for ML Performance

Choosing the right garbage collector is crucial for ML. Parallel GC often delivers highest throughput for batch ML training, with one benchmark showing it 22% faster than G1 and using 30% less memory for throughput-oriented workloads. For low-latency ML inference, ZGC or Shenandoah are preferred, offering ultra-low pause times (often sub-millisecond) even with very large heaps. G1 GC, the default since OpenJDK 9, provides a good balance for general-purpose ML applications.

The top 3

  1. ZGC vs. Shenandoah: Who Wins Ultra-Low Latency ML?: ZGC and Shenandoah are top contenders for ultra-low latency in ML, delivering millisecond-range pauses largely independent of heap size. ZGC excels in predictability and massive heap scalability (up to 16 TB), while Shenandoah prioritizes responsiveness with high allocation rates, though both incur higher CPU overhead than G1.
  2. G1's ML Performance: Why It Remains Default for Most.: G1 GC is the default for modern JVMs since JDK 9, offering a robust balance of throughput and predictable pause times (ranging from milliseconds to hundreds of milliseconds) for multi-GB heaps. It divides the heap into regions, prioritizing those with the most garbage for efficient collection, making it suitable for a wide array of ML applications.
  3. ML Heap Size Dictates Your JVM GC Champion.: The optimal JVM garbage collector for ML workloads is primarily determined by heap size and latency/throughput goals. Serial GC suits small heaps (<2GB), Parallel GC maximizes throughput for larger heaps, while G1 offers a balanced approach for medium to large heaps. For extremely large heaps (tens of GBs to TBs) and ultra-low latency, ZGC and Shenandoah are the champions, despite their higher CPU overhead.

Sources

Open the full topic