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: Improve escape analysis for variadic arguments with pointers #12006

Closed
dsnet opened this issue Aug 3, 2015 · 2 comments
Closed
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Aug 3, 2015

Using go1.5beta3.
Using a variadic argument with pointers incurs an allocation for every item even if elements of the variadic argument never escape.

Example:

package foo

import "testing"

func Foo2(a, b *int) (s int) {
    for _, v := range []*int{a, b} {
        s += *v
    }
    return s
}

func FooN(vals ...*int) (s int) {
    for _, v := range vals {
        s += *v
    }
    return s
}

func BenchmarkFoo2(b *testing.B) {
    for i := 0; i < b.N; i++ {
        var i, j int
        Foo2(&i, &j)
    }
}

func BenchmarkFooN(b *testing.B) {
    for i := 0; i < b.N; i++ {
        var i, j int
        FooN(&i, &j)
    }
}

Currently I see:

$ go test -bench . -benchmem
BenchmarkFoo1-4 300000000            5.09 ns/op        0 B/op          0 allocs/op
BenchmarkFooN-4 30000000            69.6 ns/op        32 B/op          2 allocs/op

I expect to see 0 allocs/op for BenchmarkFooN.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Aug 4, 2015
@ianlancetaylor
Copy link
Contributor

CC @dr2chase

@dr2chase dr2chase self-assigned this Sep 28, 2015
@gopherbot
Copy link

CL https://golang.org/cl/15200 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants