Go

Is Go's GC generational or compacting? What is the "Green Tea" GC?

Question 339MediumGo 1.22 to 1.25

Neither. Go's GC does not move objects, so it never compacts, and it has no generations. Reasons given by the Go team:

  • Escape analysis already keeps many short-lived values on the stack, which weakens the generational hypothesis for the heap.
  • Size-class segregated allocation keeps fragmentation low without compaction.
  • Not moving objects keeps cgo, unsafe and interior pointers simple.
  • Generational schemes need barriers on every pointer write all the time, not only during marking. Experiments showed they did not pay off.

Green Tea GC was experimental in Go 1.25 (GOEXPERIMENT=greenteagc) and became the default in Go 1.26. It keeps the same tri-color algorithm but changes how marking walks memory. Instead of chasing individual objects around the heap, it queues whole spans/pages and scans the marked small objects within each one together. That gives much better cache locality and makes vector instructions usable, cutting GC CPU cost by roughly 10-40% on many workloads. It does not change semantics: pauses, GOGC and GOMEMLIMIT behave the same.

Gotcha: a candidate who says "Go uses a generational GC like the JVM" is showing a red flag.

More on Memory, GC & Runtime Internals

All 38 Memory, GC & Runtime Internals questions