Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: Benchmarks ordering problem with generics #52002

Closed
ogau opened this issue Mar 29, 2022 · 3 comments
Closed

cmd/compile: Benchmarks ordering problem with generics #52002

ogau opened this issue Mar 29, 2022 · 3 comments
Labels
WaitingForInfo
Milestone

Comments

@ogau
Copy link

@ogau ogau commented Mar 29, 2022

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

1.18

What did you do?

Benchmarks code: https://go.dev/play/p/zNLHtksAcAS
If we run the test twice in a different order of execution of benchmarks, we will get an interesting dependency.
All subsequent code after generics degrades performance.

goos: windows
goarch: amd64
cpu: AMD Ryzen 3 PRO 2200G with Radeon Vega Graphics
BenchmarkNativeMethod-4          4061136               307.5 ns/op
BenchmarkNativeMethod-4          3827776               305.0 ns/op
BenchmarkGenericMethod-4          379663              2719 ns/op
BenchmarkGenericMethod-4          385132              2723 ns/op
goos: windows
goarch: amd64
cpu: AMD Ryzen 3 PRO 2200G with Radeon Vega Graphics
BenchmarkGenericMethod-4          442808              2858 ns/op
BenchmarkGenericMethod-4          427164              2755 ns/op
BenchmarkNativeMethod-4          2047842               571.2 ns/op
BenchmarkNativeMethod-4          2036937               593.8 ns/op

With this flags, performance both generics and non-generics becomes around ~600ns ns/op
go test -bench=. -count=2 -gcflags=all=-d=unified

What did you expect to see?

In general, I expected to see the same performance of both generic and non-generic code, but I was amazed by the behavior of the order of benchmarks.

end

@seankhliao seankhliao changed the title affected/package: Benchmarks ordering problem with generics cmd/compile: Benchmarks ordering problem with generics Mar 29, 2022
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Mar 29, 2022

On the difference between which one is placed first, I think that's just code alignment, BenchmarkNativeMethod-4 is faster when it's placed after the generic version on my computer.

@cherrymui
Copy link
Member

@cherrymui cherrymui commented Apr 5, 2022

Yeah, could be code alignment. I don't see the generated code has any difference when the order changes. Could you try a different machine? Thanks.

@cherrymui cherrymui added the WaitingForInfo label Apr 5, 2022
@cherrymui cherrymui added this to the Unplanned milestone Apr 5, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented May 5, 2022

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo
Projects
None yet
Development

No branches or pull requests

4 participants