Garbage Collection in Java: The progress since JDK 8 by Stefan Johansson

Explore Java's garbage collection evolution since JDK 8, including G1, ZGC improvements, and real-world success stories. Learn why upgrading from JDK 8 delivers major performance gains.

Key takeaways
  • Significant performance improvements have been made in Java GC since JDK 8, with G1 becoming the default collector in JDK 9

  • There are now 5 main garbage collectors in OpenJDK: Serial (low memory overhead), Parallel (high throughput), G1 (balanced performance), ZGC and Shenandoah (ultra-low latency)

  • Generational garbage collection was added to ZGC in JDK 21, becoming default in JDK 23, providing 15-40% performance improvements

  • Real-world success stories (Netflix, Mercado Libre) show significant benefits from upgrading from JDK 8 to newer versions:

    • 20-40% throughput improvements
    • 25-50% reduction in memory usage
    • 30-50% reduction in latency
  • Key GC improvements between JDK 8 and 21:

    • Streamlined threading systems
    • More efficient remember set implementations
    • Better native memory management
    • Reduced pause times
  • G1 collector improvements include:

    • Default pause target of 200ms
    • Mixed collections capability
    • Better throughput compared to JDK 8
    • More efficient memory usage
  • For most applications over 4GB heap size, G1 is recommended as the default choice

  • ZGC shows best performance for ultra-low latency requirements and large heaps, especially with the new generational mode

  • Upgrading from JDK 8 to newer versions (especially 17 or 21) is highly recommended for significant performance gains

  • Future focus areas include further latency improvements, footprint optimization, and better integration with Project Loom