-
Notifications
You must be signed in to change notification settings - Fork 18k
maps: Performance Regression in maps.Clone after Go 1.24 Refactor #72983
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
Comments
Related Issues
Related Code Changes (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
That benchmark looks invalid, the return value is discarded and can be optimized away. |
I conducted benchmarks for Go 1.23 and Go 1.24 locally based on your code. clone_test.go package clone2
import (
"maps"
"testing"
)
var g map[string]string
var m = map[string]string{
"k1": "v1",
"k2": "v2",
"k3": "v3",
"k4": "v4",
}
func BenchmarkStdClone(b *testing.B) {
for i := 0; i < b.N; i++ {
g = maps.Clone(m)
}
} Go1.24 output
Go1.23 output
|
AFAIAC in (#70836) |
So the performance regression of |
Go 1.24 refactored the map runtime using SwissTable.
When I was using Go 1.24, I found that,
compared to using a for loop to copy a map,
the performance of the built-in maps.Clone was actually worse.
At the same time, in versions prior to Go 1.24,
the performance of maps.Clone was the best.
Below is the code I used for performance testing:
Performance test results for different Go versions are as follows:
Go 1.24
Go 1.23
The results for Go 1.22 and Go 1.21 are similar to Go 1.23.
The text was updated successfully, but these errors were encountered: