Re:Padding is hard
by adonovan on Friday October 09, 2015 @12:17PM
(#10361093)
The most compact representation is not always the most efficient. If two fields in the same struct variable are accessed by different goroutines, placing them far apart so that they reside in different cache lines may avoid a great deal of contention.
[ Parent
| on HN ]
Except technically struct memory layout is currently undefined in Go so you're relying on an implementation detail.
This kind of optimized placement could in principle be done by a sufficiently smart compiler, but no such compiler exists. That's why existing compilers allow their users to control layout by, as you say, relying on an implementation detail.