-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
看内容 #19979
Comments
If the problem is the allocation, it looks like it's fixed on tip. go1.8:
tip:
|
Yes, the translation looks like it's about the allocation. |
@ALTree the issues still exist on go1.8.1 and master .what is tip version? |
@niubaoshu "tip" means "master". Same thing but different word. |
I ran the benchmark in your post on master (both on 14 April when we closed this and again, now) and the allocation is gone. Are you seeing something different? |
package main import "testing" func BenchmarkF1(b *testing.B) { func BenchmarkC1(b *testing.B) { func BenchmarkF2(b *testing.B) { func BenchmarkC2(b *testing.B) { func BenchmarkC3(b *testing.B) { func BenchmarkC4(b *testing.B) { var c1 = f1 func f1(a ...interface{}) {} go test -bench=.* -benchmem malloc_test.go on go1.8.1 version |
Looks like it may be an escape analysis limitation? Take the first two:
but in
same for go/src/cmd/compile/internal/gc/esc.go Line 1495 in fc08a19
Not sure this is expected or not, or if we want to open an issue about a possible optimization. Maybe cc @dr2chase knows. |
@ALTree OK, thank you! |
The global variable causes the pessimism here. We don't analyze the whole program to find all assignments to global variables, so although f1 is the current value of c1, maybe another function will be assigned to c1 somewhere else. So we must assume the interface{} and [1]interface{} escape. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8 darwin/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN="/Users/niubaoshu/work/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/niubaoshu/work/go"
GORACE=""
GOROOT="/Users/niubaoshu/repos/go"
GOTOOLDIR="/Users/niubaoshu/repos/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/jz/fj17bn1j3tg7s0g2yv_4wsyh0000gn/T/go-build530042778=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/2XtE2FVceD
What did you expect to see?
go test -bench="." -benchmem inter_test.go
BenchmarkT-8 2000000000 0.34 ns/op 0 B/op 0 allocs/op
BenchmarkT2-8 50000000 27.0 ns/op 8 B/op 1 allocs/op
What did you see instead?
为什么BenchmarkT2-8 需要分配一次内存?
猜测是正常的函数调用做了优化,所以不需要分配内存。
但是为什么var fff = ccc 就想要分配内存了
The text was updated successfully, but these errors were encountered: