Go 1.26 made Green Tea the default GC. We observe its cache-friendliness with perf, visualize the heap to see how Go allocates, and poke at a sparse-page problem a non-moving collector like Go's struggles with.You are getting early access to this article as a subscriber. Your support makes articles like this possible. Thank you.Go 1.25, released last year, introduced a new garbage collector: Green Tea. And in Go 1.26, released a few months ago, Green Tea became the default. That linked article is excellent. We’ll recap it and take a look at a few programs that benefit the most. And we’ll look at some programs that don’t benefit, that trigger Go’s residual garbage collector bugaboo: its non-moving collector cannot reclaim sparse pages.Taking a step back, Go manages memory by allocating objects of the same size class (an object’s size is rounded up to the nearest size class) within a contiguous chunk (or span in Go terminology) of one or more 8KiB pages. Size-segregated allocation is common in some malloc implementations (like tcmalloc, which Go’s allocator descends from).Let’s observe this happening in Go, and then compare it with C#. We’ll randomly allocate objects of three different sizes (small, medium and large). Then we’ll check their heap addresses, walk the address space and print out when we hit one of our objects, one character printed out for each 32-bytes we walk.First install Go and C#.sudo apt update -y sudo apt-get install -y dotnet-sdk-10.0 curl -fsSL https://go.dev/dl/go1.26.0.linux-amd64.tar.gz | sudo tar -C /usr/local -xz export PATH=$PATH:/usr/local/go/bin Here’s the pseudocode we’re going for.struct Small { a [32]byte } struct Medium { a [64]byte } struct Large { a [128]byte } constructors = [Small, Medium, Large] live = [] # stop objects from being collected for i in range(100): live.push(new constructors[rand() % len(constructors)]) for pass in [0, 1]: if pass == 1: runtime.gc() # trigger the GC records = [] for obj in live: records.push((runtim...
First seen: 2026-07-24 21:31
Last seen: 2026-07-26 21:06