Skip to content

cmd/compile: dip in small struct copy performance in go1.17beta #47074

@zigo101

Description

@zigo101

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

$ go version
go version go1.17beta1 linux/amd64

Does this issue reproduce with the latest release?

Not for go1.16.5 and tip.

What did you do?

package foo

import (
    "testing"
)

const N = 8192

var struct3_0 struct{a, b, c int}

func Benchmark_CopyStruct_3_fields(b *testing.B) {
    var struct3_1 struct{a, b, c int}
    for i := 0; i < b.N; i++ {
        for range [N]struct{}{} {
            struct3_0 = struct3_1
        }
    }
}

func Benchmark_xxx(b *testing.B) {
    for i := 0; i < b.N; i++ {
    }
}

func Benchmark_yyy(b *testing.B) {
    for i := 0; i < b.N; i++ {
    }
}

What did you expect to see?

cpu: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
Benchmark_CopyStruct_3_fields-4   	  183609	      6357 ns/op
Benchmark_xxx-4                   	1000000000	         0.4014 ns/op
Benchmark_yyy-4                   	1000000000	         0.4130 ns/op

What did you see instead?

cpu: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
Benchmark_CopyStruct_3_fields-4   	   93883	     12407 ns/op
Benchmark_xxx-4                   	1000000000	         0.4014 ns/op
Benchmark_yyy-4                   	1000000000	         0.4130 ns/op

It at least one in the Benchmark_xxx or Benchmark_yyy is removed, then the result is normal.
Otherwise, the result is double.

The problem doesn't exist in go1.16.5 and tip. I don't know whether or not it is fixed in the go1.17 release branch.
I didn't find the go1.17 release branch in the repo, so I haven't tested it.

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions