diff options
| author | Josh Bleecher Snyder <josharian@gmail.com> | 2018-12-02 10:15:35 -0800 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2019-02-27 18:07:25 +0000 |
| commit | 694cd005c3943027a4533a0a534837108ccd66f6 (patch) | |
| tree | 04de439553a192e17473fdd12d0f0744a3f57d3a /src/runtime | |
| parent | c33a9511e7ba79177c256e1ff9d7c952ab80104f (diff) | |
| download | go-694cd005c3943027a4533a0a534837108ccd66f6.tar.xz | |
runtime: speed up ifaceeq for direct ifaces
name old time/op new time/op delta
EfaceCmpDiff-8 421ns ± 3% 299ns ± 3% -28.93% (p=0.000 n=92+94)
EfaceCmpDiffIndirect-8 497ns ± 4% 496ns ± 3% ~ (p=0.840 n=98+92)
Change-Id: Id1a8c779413ba35ab0f58d055870b6a0714b51b7
Reviewed-on: https://go-review.googlesource.com/c/152163
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/alg.go | 8 | ||||
| -rw-r--r-- | src/runtime/runtime_test.go | 12 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go index 887dbebdeb..1c6795a1fa 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -224,7 +224,10 @@ func efaceeq(t *_type, x, y unsafe.Pointer) bool { panic(errorString("comparing uncomparable type " + t.string())) } if isDirectIface(t) { - return eq(noescape(unsafe.Pointer(&x)), noescape(unsafe.Pointer(&y))) + // Direct interface types are ptr, chan, map, func, and single-element structs/arrays thereof. + // Maps and funcs are not comparable, so they can't reach here. + // Ptrs, chans, and single-element items can be compared directly using ==. + return x == y } return eq(x, y) } @@ -238,7 +241,8 @@ func ifaceeq(tab *itab, x, y unsafe.Pointer) bool { panic(errorString("comparing uncomparable type " + t.string())) } if isDirectIface(t) { - return eq(noescape(unsafe.Pointer(&x)), noescape(unsafe.Pointer(&y))) + // See comment in efaceeq. + return x == y } return eq(x, y) } diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go index 8263d4059a..5ea9cbd88a 100644 --- a/src/runtime/runtime_test.go +++ b/src/runtime/runtime_test.go @@ -70,6 +70,18 @@ func BenchmarkEfaceCmpDiff(b *testing.B) { } } +func BenchmarkEfaceCmpDiffIndirect(b *testing.B) { + efaceCmp1 = [2]int{1, 2} + efaceCmp2 = [2]int{1, 2} + for i := 0; i < b.N; i++ { + for j := 0; j < 100; j++ { + if efaceCmp1 != efaceCmp2 { + b.Fatal("bad comparison") + } + } + } +} + func BenchmarkDefer(b *testing.B) { for i := 0; i < b.N; i++ { defer1() |
