{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/19979","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/19979/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/19979/comments","events_url":"https://api.github.com/repos/golang/go/issues/19979/events","html_url":"https://github.com/golang/go/issues/19979","id":221809398,"number":19979,"title":"看内容","user":{"login":"niubaoshu","id":962591,"avatar_url":"https://avatars2.githubusercontent.com/u/962591?v=3","gravatar_id":"","url":"https://api.github.com/users/niubaoshu","html_url":"https://github.com/niubaoshu","followers_url":"https://api.github.com/users/niubaoshu/followers","following_url":"https://api.github.com/users/niubaoshu/following{/other_user}","gists_url":"https://api.github.com/users/niubaoshu/gists{/gist_id}","starred_url":"https://api.github.com/users/niubaoshu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niubaoshu/subscriptions","organizations_url":"https://api.github.com/users/niubaoshu/orgs","repos_url":"https://api.github.com/users/niubaoshu/repos","events_url":"https://api.github.com/users/niubaoshu/events{/privacy}","received_events_url":"https://api.github.com/users/niubaoshu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-04-14T13:29:26Z","updated_at":"2017-05-22T09:12:46Z","closed_at":"2017-04-14T14:11:19Z","body":"Please answer these questions before submitting your issue. Thanks!\r\n\r\n### What version of Go are you using (`go version`)?\r\ngo version go1.8 darwin/amd64\r\n\r\n### What operating system and processor architecture are you using (`go env`)?\r\nGOARCH=\"amd64\"\r\nGOBIN=\"/Users/niubaoshu/work/go/bin\"\r\nGOEXE=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"darwin\"\r\nGOOS=\"darwin\"\r\nGOPATH=\"/Users/niubaoshu/work/go\"\r\nGORACE=\"\"\r\nGOROOT=\"/Users/niubaoshu/repos/go\"\r\nGOTOOLDIR=\"/Users/niubaoshu/repos/go/pkg/tool/darwin_amd64\"\r\nGCCGO=\"gccgo\"\r\nCC=\"clang\"\r\nGOGCCFLAGS=\"-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\"\r\nCXX=\"clang++\"\r\nCGO_ENABLED=\"1\"\r\nPKG_CONFIG=\"pkg-config\"\r\nCGO_CFLAGS=\"-g -O2\"\r\nCGO_CPPFLAGS=\"\"\r\nCGO_CXXFLAGS=\"-g -O2\"\r\nCGO_FFLAGS=\"-g -O2\"\r\nCGO_LDFLAGS=\"-g -O2\"\r\n### What did you do?\r\n\r\nIf possible, provide a recipe for reproducing the error.\r\nA complete runnable program is good.\r\nA link on play.golang.org is best.\r\n\r\nhttps://play.golang.org/p/2XtE2FVceD\r\n\r\n### What did you expect to see?\r\ngo test -bench=\".\" -benchmem  inter_test.go\r\nBenchmarkT-8    \t2000000000\t         0.34 ns/op\t       0 B/op\t       0 allocs/op\r\nBenchmarkT2-8     50000000\t        27.0 ns/op\t       8 B/op\t       1 allocs/op\r\n\r\n### What did you see instead?\r\n为什么BenchmarkT2-8 需要分配一次内存？\r\n猜测是正常的函数调用做了优化，所以不需要分配内存。\r\n但是为什么var fff = ccc  就想要分配内存了 \r\n\r\n> Why does BenchmarkT2-8 need to allocate memory once?\r\n> Guess that the normal function call is optimized so there is no need to allocate memory.\r\n> But why is var fff = ccc want to allocate memory\r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/303044388","html_url":"https://github.com/golang/go/issues/19979#issuecomment-303044388","issue_url":"https://api.github.com/repos/golang/go/issues/19979","id":303044388,"user":{"login":"ALTree","id":3586803,"avatar_url":"https://avatars1.githubusercontent.com/u/3586803?v=3","gravatar_id":"","url":"https://api.github.com/users/ALTree","html_url":"https://github.com/ALTree","followers_url":"https://api.github.com/users/ALTree/followers","following_url":"https://api.github.com/users/ALTree/following{/other_user}","gists_url":"https://api.github.com/users/ALTree/gists{/gist_id}","starred_url":"https://api.github.com/users/ALTree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ALTree/subscriptions","organizations_url":"https://api.github.com/users/ALTree/orgs","repos_url":"https://api.github.com/users/ALTree/repos","events_url":"https://api.github.com/users/ALTree/events{/privacy}","received_events_url":"https://api.github.com/users/ALTree/received_events","type":"User","site_admin":false},"created_at":"2017-05-22T09:12:46Z","updated_at":"2017-05-22T09:12:46Z","body":"Looks like it may be an escape analysis limitation? Take the first two:\r\n\r\n```\r\nfunc BenchmarkF1(b *testing.B) {\r\n\tfor i := 0; i < b.N; i++ {\r\n\t\tf1(i)\r\n\t}\r\n}\r\n\r\nfunc BenchmarkC1(b *testing.B) {\r\n\tfor i := 0; i < b.N; i++ {\r\n\t\tc1(i)\r\n\t}\r\n}\r\n\r\nvar c1 = f1\r\nfunc f1(a ...interface{}) {}\r\n```\r\n\r\n`-m -m` says that `i` in the `f1(i)` does not escape:\r\n\r\n```\r\nBenchmarkF1 i does not escape\r\n```\r\n\r\nbut in `c1(i)` it does:\r\n\r\n```\r\ni escapes to heap\r\n\tfrom c1(i) (parameter to indirect call) at ./prova_test.go:13:5\r\n```\r\n\r\nsame for `f2(i)` and `c2(i)`. This is where it happens:\r\n\r\nhttps://github.com/golang/go/blob/fc08a19cef1b54cf6aad2fc1f8a298458d2e8d95/src/cmd/compile/internal/gc/esc.go#L1495\r\n\r\nNot sure this is expected or not, or if we want to open an issue about a possible optimization. Maybe cc @dr2chase knows."}}
{"actor":{"display_login":"ALTree"}}