Skip to content

runtime,cmd/compile: miss an optimization case for "struct{byte}" #49879

@zigo101

Description

@zigo101

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

$ go version
go version go1.17.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package interfaces

import "testing"

var r interface{}

type T8 struct{n byte}
func Benchmark_ByteField(b *testing.B) {
	for i := 0; i < b.N; i++ { r = T8{byte(i&255)} }
}

type T16 struct{n int16}
func Benchmark_Int16Field(b *testing.B) {
	for i := 0; i < b.N; i++ { r = T16{int16(i&255)} }
}

type T32 struct{n int32}
func Benchmark_Int32Field(b *testing.B) {
	for i := 0; i < b.N; i++ { r = T32{int32(i&255)} }
}

type T64 struct{n int64}
func Benchmark_Int64Field(b *testing.B) {
	for i := 0; i < b.N; i++ { r = T64{int64(i&255)} }
}

What did you expect to see?

Similar value boxing costs.

What did you see instead?

Boxing struct{n byte} values is more costly than others.

goos: linux
goarch: amd64
Benchmark_ByteField-4    	60815828	        19.89 ns/op
Benchmark_Int16Field-4   	341708020	         3.424 ns/op
Benchmark_Int32Field-4   	348755539	         3.403 ns/op
Benchmark_Int64Field-4   	348057927	         3.637 ns/op

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions