Navigation Menu

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

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

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

g7r opened this issue May 22, 2019 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Performance
Milestone

Comments

@g7r
Copy link
Contributor

g7r 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
Copy link
Contributor Author

g7r commented May 22, 2019

I'll submit a change to fix the issue.

@gopherbot
Copy link

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 The path to resolution is known, but the work has not been done. label May 22, 2019
tomocy pushed a commit to tomocy/go that referenced this issue Sep 1, 2019
directlyAssignable invoked rtype.Name() just to compare its result
to empty string. We really only need to check whether rtype has
name. It can be done much cheaper, by checking tflagNamed.

Benchmark: https://play.golang.org/p/V2BzESPuf2w
name                   old time/op  new time/op  delta
DirectlyAssignable-12  32.7ns ± 6%   6.6ns ± 6%  -79.80%  (p=0.008 n=5+5)

Fixes golang#32186

Change-Id: I1a2a167dbfddf319fba3015cb6a011bf010f99a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/178518
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
t4n6a1ka pushed a commit to t4n6a1ka/go that referenced this issue Sep 5, 2019
directlyAssignable invoked rtype.Name() just to compare its result
to empty string. We really only need to check whether rtype has
name. It can be done much cheaper, by checking tflagNamed.

Benchmark: https://play.golang.org/p/V2BzESPuf2w
name                   old time/op  new time/op  delta
DirectlyAssignable-12  32.7ns ± 6%   6.6ns ± 6%  -79.80%  (p=0.008 n=5+5)

Fixes golang#32186

Change-Id: I1a2a167dbfddf319fba3015cb6a011bf010f99a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/178518
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@golang golang locked and limited conversation to collaborators Aug 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Performance
Projects
None yet
Development

No branches or pull requests

4 participants