False sharing is a performance mistake: independent variables share a cache line, so updates from different cores repeatedly invalidate each other's cached data. The code can be race-free yet unexpectedly slow. section 12.2 section 12.11
func count(inputs []Input) Result {
wg := sync.WaitGroup{}
wg.Add(2)
result := Result{} #1
go func() {
for i := 0; i < len(inputs); i++ {
result.sumA += inputs[i].a #2
}
wg.Done()
}()
go func() {
for i := 0; i < len(inputs); i++ {
result.sumB += inputs[i].b #3
}
wg.Done()
}()
wg.Wait()
return result
}
Two goroutines independently accumulate sumA and sumB in one Result. Although each goroutine owns its variable, the adjacent fields can occupy the same memory block. section 12.2
A CPU usually copies memory in 64-byte cache lines rather than individual words. L1 data caches are specific to physical cores, so each core may hold a copy of the line containing both fields. Updating one field then invalidates the other core's copy, even though the goroutines never share a variable. section 12.11 section 12.2
type Result struct {
sumA int64
_ [56]byte #1
sumB int64
}
Padding places sumA and sumB in different memory blocks, reducing cache-line interference when separate cores update them concurrently. section 12.2
Use padding when independent, frequently updated fields run concurrently and profiling shows this bottleneck. Otherwise, preserve the simpler layout; false sharing is a performance issue, not a data-race diagnosis. section 12.2 section 12.11

