-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
Consider the following benchmark:
func Benchmark(b *testing.B) {
m := map[string]int{}
k := []byte("hello, world")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
m[string(k)] = 1
}
}
This currently prints:
Benchmark 37319388 29.83 ns/op 16 B/op 1 allocs/op
I expect this to not allocate since it is reusing the same map entry every time.
The very first mapassign
will need to allocate the string on heap, but subsequent operations should not need to.
This is related to #45045, which made this optimization harder.
\cc @randall77 @cuonglm
bboreham
Metadata
Metadata
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
Todo