cmd/compile: statically remove type switch in instantiated generic code #57072
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
Using Go1.19
Consider this benchmark, which has three functions:
lessUTF16
is a generic function that operates on either[]byte
orstring
. It relies on a type switch to call eitherutf8.DecodeRune
orutf8.DecodeRuneInString
.lessUTF16Bytes
is identical tolessUTF16
but is manually instantiated for[]byte
.lessUTF16String
is identical tolessUTF16
but is manually instantiated forstring
.The diff from
lessUTF16
tolessUTF16Bytes
is:Similarly, the diff from
lessUTF16
tolessUTF16String
is:I would expect
lessUTF16[[]byte]
to perform identically tolessUTF16Bytes
andlessUTF16[string]
to perform identically tolessUTF16String
since the compiler can prove that only one of the cases are possibly executable. However, that is not what the benchmarks show:\cc @randall77
The text was updated successfully, but these errors were encountered: