]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: improve interface type switches
authorKeith Randall <khr@golang.org>
Sat, 2 Sep 2023 03:32:07 +0000 (20:32 -0700)
committerKeith Randall <khr@golang.org>
Fri, 6 Oct 2023 15:42:30 +0000 (15:42 +0000)
commit28f4ea16a240af6c5a417e20be77745329f817f1
treea298be53ac70ba58b561a023c8ec41d2e16e8dfc
parent10da3b64af1aebfd146fa3b7ecf765ee1b0f0d7d
cmd/compile: improve interface type switches

For type switches where the targets are interface types,
call into the runtime once instead of doing a sequence
of assert* calls.

name                                 old time/op  new time/op  delta
SwitchInterfaceTypePredictable-24    26.6ns ± 1%  25.8ns ± 2%  -2.86%  (p=0.000 n=10+10)
SwitchInterfaceTypeUnpredictable-24  39.3ns ± 1%  37.5ns ± 2%  -4.57%  (p=0.000 n=10+10)

Not super helpful by itself, but this code organization allows
followon CLs that add caching to the lookups.

Change-Id: I7967f85a99171faa6c2550690e311bea8b54b01c
Reviewed-on: https://go-review.googlesource.com/c/go/+/526657
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
14 files changed:
src/cmd/compile/internal/ir/node.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/ir/op_string.go
src/cmd/compile/internal/ir/stmt.go
src/cmd/compile/internal/ir/symtab.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/test/switch_test.go
src/cmd/compile/internal/typecheck/_builtin/runtime.go
src/cmd/compile/internal/typecheck/builtin.go
src/cmd/compile/internal/walk/stmt.go
src/cmd/compile/internal/walk/switch.go
src/internal/abi/switch.go [new file with mode: 0644]
src/runtime/iface.go
test/codegen/switch.go