Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync/atomic: operations cause unnecessary escapes #16241

aclements opened this issue Jul 1, 2016 · 0 comments


None yet
6 participants
Copy link

commented Jul 1, 2016

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)

@aclements aclements added this to the Go1.8 milestone Jul 1, 2016

@quentinmit quentinmit added the NeedsFix label Oct 10, 2016

@rsc rsc modified the milestones: Go1.9Early, Go1.8 Oct 18, 2016

@bradfitz bradfitz modified the milestones: Go1.10Early, Go1.9Early May 3, 2017

@bradfitz bradfitz modified the milestones: Go1.10Early, Go1.10 Jun 14, 2017

@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017

@bradfitz bradfitz modified the milestones: Go1.11, Go1.12 May 18, 2018

@bradfitz bradfitz added this to the Go1.12 milestone Jun 1, 2018

@odeke-em odeke-em modified the milestones: Go1.12, Go1.13 Feb 4, 2019

@odeke-em odeke-em removed the early-in-cycle label Feb 4, 2019

@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.