Menu

ZGC vs G1: Trading CPU for Pause-Free Memory Reclamation
📰

ZGC vs G1: Trading CPU for Pause-Free Memory Reclamation

DEV Community: java·gxqwb·14 days ago
#aKLPJrgm
#devtojava#devto#dev#heap#pause
Long article (992 words) — no AI summary yet.
Reading 0:00
15s threshold

A Java service that caches a few million objects eventually has to throw them away, and how it does so determines whether users see a smooth response time or a periodic freeze. For years the default collector was G1, which broke the heap into regions and cleaned a few at a time to keep pauses short. ZGC changed the bargain: it moves objects while the program is still running, so even a heap measured in terabytes pauses for roughly the time it takes to stop the threads at a safepoint.

G1 keeps pause times in the tens of milliseconds by collecting in small region increments, while ZGC keeps them under a millisecond regardless of heap size by doing the compaction work concurrently with the application — the price is extra CPU and heap headroom.

The decision is not about which collector is newer.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.