Oct 29

Some quick notes on garbage collection

Just cribbing some stuff from this HN thread for later reference — and possibly, dear reader, your interest!

  • Go recently gained a significantly faster garbage collector with “typical worst-case” performance of 100 usec.
  • It still "stops the world” to do so. In order to stop all threads quickly, it uses page poisoning: have threads read from a page at GC-safe points (such as on function entry); when GC is required the collector can just install a segfault handler, unmap the page, wait for all threads to segfault, do the collection and restart the threads. (This thread-stopping technique is unrelated to the overall GC speed-up, which is about efficiently avoiding stack re-scanning)
  • The page poisoning technique trades off fast GC and unnecessary memory accesses. For example, a loop which does not make function calls can apparently stall GC.
  • Apparently the changes increase overall time in GC — to 20% of total runtime for one poster.