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

reflect: directlyAssignable doesn't need rtype.Name() #32186

Open
g7r opened this issue May 22, 2019 · 2 comments

Comments

Projects
None yet
4 participants
@g7r
Copy link

commented May 22, 2019

What version of Go are you using (go version)?

$ go version
go version devel +06b0babf31 Wed May 22 12:54:00 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sz/.cache/go-build"
GOENV="/home/sz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/sz/go"
GOPROXY="direct"
GOROOT="/home/sz/src/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/home/sz/src/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build870897326=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Benchmark: https://play.golang.org/p/V2BzESPuf2w
Benchmark results:

$ benchstat old_test.txt new_test.txt
name                   old time/op  new time/op  delta
DirectlyAssignable-12  32.7ns ± 6%   6.6ns ± 6%  -79.80%  (p=0.008 n=5+5)

What did you expect to see?

I honestly expect AssignableTo to be as fast as possible.

What did you see instead?

I see that AssignableTo invokes directlyAssignable. And directlyAssignable performs more work than it really needs. directlyAssignable retrieves rtype names and checks whether they are equal to empty string. Retrieving the names isn't required for that. We can just check the flag tflagNamed.

@g7r

This comment has been minimized.

Copy link
Author

commented May 22, 2019

I'll submit a change to fix the issue.

@gopherbot

This comment has been minimized.

Copy link

commented May 22, 2019

Change https://golang.org/cl/178518 mentions this issue: reflect: directlyAssignable doesn't need rtype.Name()

@bradfitz bradfitz added this to the Go1.14 milestone May 22, 2019

@bcmills bcmills added the NeedsFix label May 22, 2019

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