-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Open
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
Go version
go1.22.0
Output of go env in your module/workspace:
GOOS=linux
GOARCH=amd64What did you do?
package main
import "testing"
type Option interface{ isOption() }
type maxWindowSize uint64
func (maxWindowSize) isOption() {}
func MaxWindowSize(n uint64) Option { return maxWindowSize(n) }
var opt Option
func BenchmarkFunc(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
opt = MaxWindowSize(1024)
}
}
func BenchmarkDirect(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
opt = maxWindowSize(1024)
}
}What did you see happen?
I see:
BenchmarkFunc-24 109294134 11.11 ns/op 8 B/op 1 allocs/op
BenchmarkDirect-24 1000000000 0.4708 ns/op 0 B/op 0 allocs/op
What did you expect to see?
I expect to see:
BenchmarkFunc-24 1000000000 0.4708 ns/op 0 B/op 0 allocs/op
BenchmarkDirect-24 1000000000 0.4708 ns/op 0 B/op 0 allocs/op
The MaxWindowSize function is inlineable, so I would expect it to be identical to declaring a maxWindowSize literal directly.
This seems to be an odd interaction between static allocations, constant propagation, and inlining. I'm not sure if the title properly reflects what's going on.
mvdan, qiulaidongfeng, ericlagergren and CAFxX
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
Status
No status