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

Closed
aclements opened this issue Jul 1, 2016 · 1 comment
Closed

sync/atomic: operations cause unnecessary escapes #16241

aclements opened this issue Jul 1, 2016 · 1 comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Performance
Milestone

Comments

@aclements
Copy link
Member

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 The path to resolution is known, but the work has not been done. 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 added early-in-cycle A change that should be done early in the 3 month dev cycle. and removed early-in-cycle A change that should be done early in the 3 month dev cycle. labels Jun 14, 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 A change that should be done early in the 3 month dev cycle. label Feb 4, 2019
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
ijsong added a commit to kakao/varlog that referenced this issue Aug 5, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](https://jira.daumkakao.com/browse/VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 8, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](https://jira.daumkakao.com/browse/VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 9, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 10, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 10, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
ijsong added a commit to kakao/varlog that referenced this issue Aug 10, 2022
Using atomic operations makes a variable to escape to the heap.
See golang/go#16241.
This PR changes reportCommitBase to use shared mutex rather than atomic.

Resolves [#VARLOG-529](VARLOG-529).
@seankhliao seankhliao added this to the Unplanned milestone Aug 20, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/462298 mentions this issue: sync/atomic: mark all but unsafe.Pointer functions noescape

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Performance
Projects
None yet
Development

No branches or pull requests

8 participants