-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
The atomic Load* and Store* operations cause their argument to unnecessarily escape. For example, in the following program, x is heap allocated:
package main
import "sync/atomic"
func main() {
var x int32
atomic.StoreInt32(&x, 42)
}
This is fairly low priority, since it's silly to use atomics on variables unless they're shared, and if the variable is shared it has to be in the heap anyway, but we should fix it since the same code path may be used for both shared and unshared data (there will obviously be unnecessary overhead from the atomics, but we can address the additional heap allocation overhead). This has been right for the runtime-internal atomics for some time, and we should simply copy what they do. In particular, we need to be careful with the *Pointer functions, since their values potentially do escape.
Pointed out by OneOfOne/lfchan#3 (comment)