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

cmd/compile: unexpected escape when ranging over an anonymous struct containing functions #21709

Closed
twmb opened this issue Aug 31, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@twmb
Copy link
Contributor

commented Aug 31, 2017

Please answer these questions before submitting your issue. Thanks!

What did you do?

https://play.golang.org/p/WzFvL4aqML
go test -bench . -benchmem

What did you expect to see?

BenchmarkB to have 0 allocations

What did you see instead?

goos: darwin
goarch: amd64
BenchmarkA-4   	300000000	         4.75 ns/op	       0 B/op	       0 allocs/op
BenchmarkB-4   	20000000	        55.7 ns/op	      16 B/op	       1 allocs/op
PASS
ok  	_/Users/twmb/debug/alloc	3.089s

System details

go version go1.9 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/twmb/go"
GORACE=""
GOROOT="/Users/twmb/go/go"
GOTOOLDIR="/Users/twmb/go/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_m/6_qc8cr574ddsc7j2ytvtcyc0000gn/T/go-build699981013=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9
uname -v: Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.12.6
BuildVersion:	16G29
lldb --version: lldb-370.0.42
  Swift-3.1

@ianlancetaylor ianlancetaylor changed the title Unexpected allocations when ranging over an anonymous struct containing functions cmd/compile: unexpected escape when ranging over an anonymous struct containing functions Aug 31, 2017

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Aug 31, 2017

Building with -m I see

s.Inc escapes to heap

in BenchmarkB with no corresponding annotation in BenchmarkA. I believe that is the source of the allocation. I don't know why it escapes in BenchmarkB but not in BenchmarkA.

@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Aug 31, 2017

@gopherbot

This comment has been minimized.

Copy link

commented Nov 29, 2017

Change https://golang.org/cl/80740 mentions this issue: cmd/compile: fix loop depth of range expression in escape analysis

@gopherbot gopherbot closed this in dbb1d19 Nov 30, 2017

@golang golang locked and limited conversation to collaborators Nov 30, 2018

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