-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Performanceearly-in-cycleA change that should be done early in the 3 month dev cycle.A change that should be done early in the 3 month dev cycle.
Milestone
Description
- What version of Go are you using (
go version
)?
go version devel +0a9595f Tue May 17 18:46:03 2016 -0400 linux/amd64 - What operating system and processor architecture are you using (
go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/austin/r/go"
GORACE=""
GOROOT="/home/austin/go.dev"
GOTOOLDIR="/home/austin/go.dev/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build366275436=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1" - What did you do?
package main
var sink [100]byte
func test(args ...interface{}) {
for _, arg := range args {
switch arg := arg.(type) {
case string:
// copy causes args to escape and causes the
// convT2E in main to allocate.
copy(sink[:], arg)
// Manually copying means args does not escape
// and the convT2E in main does not allocate.
//for i := 0; i < len(arg); i++ {
// sink[i] = arg[i]
//}
}
}
}
func main() {
test("abc")
}
- What did you expect to see?
I expected "abc" inmain
to not escape and the conversion tointerface{}
to not allocate. - What did you see instead?
If I usecopy
intest
, escape analysis determines that arg's content escapes, which causes the args slice to escape, which causes theconvT2E
inmain
to allocate. However, if I do the copy "manually" by looping over the string, args does not escape, and theconvT2E
happens on the stack.
/cc @dr2chase @randall77
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Performanceearly-in-cycleA change that should be done early in the 3 month dev cycle.A change that should be done early in the 3 month dev cycle.