Description
Go version
1.22
Output of go env
in your module/workspace:
n/a
What did you do?
I double checked the math in this blog post about the garbage collector and it seems incorrect. https://tip.golang.org/doc/gc-guide
Meanwhile, target heap memory is defined as:
Target heap memory = Live heap + (Live heap + GC roots) * GOGC / 100
As an example, consider a Go program with a live heap size of 8 MiB, 1 MiB of goroutine stacks, and 1 MiB of pointers in global variables. Then, with a GOGC value of 100, the amount of new memory that will be allocated before the next GC runs will be 10 MiB, or 100% of the 10 MiB of work, for a total heap footprint of 18 MiB. With a GOGC value of 50, then it'll be 50%, or 5 MiB. With a GOGC value of 200, it'll be 200%, or 20 MiB.
What did you see happen?
I see two out of three equations in the paragraph as being incorrect.
Correct
*8 + (8+1+1)100/100 = 18
**Incorrect
8 + (8+1+1)*200/100 = 20
8 + (8+1+1)50/100 = 5*
What did you expect to see?
I attached some screenshots from the online calculator. When GOGC is 50, with the given numbers, the expected total should be 13 MiB (not 5). When GOGC is 200, with the given numbers, the expected total should be 28 MiB (not 20).