The Go garbage collector scans for pointers to free referenced objects in every allocated structures up to the last field that potentially reference something.
By moving reference field to the beginning of the structure this allows the GC to fetch less often from memory as they can fetch the whole referenced part of the structure in one operation if it fits the CPU cacheline size
For example, handlers.Conversation became a consolidated 48 bytes of pointers instead of 72 bytes. If we follow 10 000 conversations this may well reduce the GC interruption time.
Of course, they are numerous factors (like a change of the Go runtime GC implementation in the future) that can make this optimisation useless, but as far as Go 1.19, there is no harm to try.
Others seldom allocated structures are not pointer-aligned, but as changing their order may break users using unnamed fields, better not to change them.
The Go garbage collector scans for pointers to free referenced objects in every allocated structures up to the last field that potentially reference something.
By moving reference field to the beginning of the structure this allows the GC to fetch less often from memory as they can fetch the whole referenced part of the structure in one operation if it fits the CPU cacheline size
For example,
handlers.Conversation
became a consolidated 48 bytes of pointers instead of 72 bytes. If we follow 10 000 conversations this may well reduce the GC interruption time.Of course, they are numerous factors (like a change of the Go runtime GC implementation in the future) that can make this optimisation useless, but as far as Go 1.19, there is no harm to try.
Others seldom allocated structures are not pointer-aligned, but as changing their order may break users using unnamed fields, better not to change them.