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

runtime: convT2E called for function value #19335

Closed
cstockton opened this issue Mar 1, 2017 · 3 comments
Closed

runtime: convT2E called for function value #19335

cstockton opened this issue Mar 1, 2017 · 3 comments

Comments

@cstockton
Copy link

@cstockton cstockton commented Mar 1, 2017

Go 1.8 amd64 linux when running the below program convT2E is called for BenchmarkEfaceFnVal but not for BenchmarkEfaceFn.

Program:

package main

import "testing"

func efaceFn(v interface{}) {
	return
}

func BenchmarkEfaceFnVal(b *testing.B) {
	b.ReportAllocs()

	efaceFnVal := efaceFn
	for i := 0; i < b.N; i++ {
		efaceFnVal(0x1)
	}
}

func BenchmarkEfaceFn(b *testing.B) {
	b.ReportAllocs()

	for i := 0; i < b.N; i++ {
		efaceFn(0x1)
	}
}

Result:

Name Iterations ns/op B/op allocs/op
BenchmarkEfaceFnVal-24 20000000 60.8 ns/op 8 B/op 1 allocs/op
BenchmarkEfaceFn-24 2000000000 0.48 ns/op 0 B/op 0 allocs/op
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Mar 1, 2017

@bradfitz bradfitz added the Performance label Mar 1, 2017
@bradfitz bradfitz added this to the Go1.9Maybe milestone Mar 1, 2017
@randall77

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented Mar 1, 2017

This is fixed at tip.

In BenchmarkEfaceFn, the call gets inlined and the conversion get compiled completely away.

In BenchmarkEfaceFnVal, the call still has to happen (we have no devirtualization of calls at the moment), but the conversion to interface now happens statically at compile time.

BenchmarkEfaceFnVal-8   	1000000000	         2.33 ns/op	       0 B/op	       0 allocs/op
BenchmarkEfaceFn-8      	2000000000	         0.52 ns/op	       0 B/op	       0 allocs/op
@randall77 randall77 closed this Mar 1, 2017
@cstockton

This comment has been minimized.

Copy link
Author

@cstockton cstockton commented Mar 1, 2017

@randall77 Sorry I didn't check tip first, should have, thanks for the quick response

@golang golang locked and limited conversation to collaborators Mar 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.