You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
maps: Performance Regression in maps.Clone after Go 1.24 Refactor #72983
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.
That benchmark looks invalid, the return value is discarded and can be optimized away.
Ensuring the value is retained produces more consistent results: https://go.dev/play/p/jBtvROSBTzV
That benchmark looks invalid, the return value is discarded and can be optimized away. Ensuring the value is retained produces more consistent results: https://go.dev/play/p/jBtvROSBTzV
I conducted benchmarks for Go 1.23 and Go 1.24 locally based on your code.
Below is the test code. Using the same test code, I tested it with Go 1.24 and Go 1.23 separately.
For the same maps.Clone code, the execution speed in Go 1.23 is twice that of Go 1.24.
Activity
gabyhelp commentedon Mar 21, 2025
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
seankhliao commentedon Mar 21, 2025
That benchmark looks invalid, the return value is discarded and can be optimized away.
Ensuring the value is retained produces more consistent results: https://go.dev/play/p/jBtvROSBTzV
1911860538 commentedon Mar 21, 2025
I conducted benchmarks for Go 1.23 and Go 1.24 locally based on your code.
Below is the test code. Using the same test code, I tested it with Go 1.24 and Go 1.23 separately.
For the same maps.Clone code, the execution speed in Go 1.23 is twice that of Go 1.24.
clone_test.go
Go1.24 output
Go1.23 output
mateusz834 commentedon Mar 21, 2025
AFAIAC in
go1.24themaps.Cloneis not optimized specially as it was for non-swiss maps in 1.23(#70836)
1911860538 commentedon Mar 21, 2025
So the performance regression of
maps.Cloneis a fact.