-
Notifications
You must be signed in to change notification settings - Fork 18k
maps: make Clone more efficient by adding support in the runtime package #58740
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
when this proposal is accepted, I will send a cl to implement it. |
Is this necessary with the new Where does the assertion that it's inefficient come from? |
using copy which implement by me that i will send it later to clone a new map is faster than for range copy like implement in maps.Clone. here is the benchmark output and benchmark code:
|
Whatever you are doing in your version of |
Change https://go.dev/cl/471400 mentions this issue: |
@ianlancetaylor please help to check whether the cl is ok. |
I proposed this years and years ago on the Go Nuts mailing list, but it seems totally moot now that maps.Clone has been accepted into Go 1.21. |
this cl reduce the cost of time that clone a one million kv(map[int]int) from 60ms to 3ms. |
name old time/op new time/op delta MapClone-10 66.0ms ± 1% 3.2ms ± 4% -95.13% (p=0.000 n=9+10) name old alloc/op new alloc/op delta MapClone-10 40.2MB ± 0% 40.2MB ± 0% +0.00% (p=0.000 n=10+8) name old allocs/op new allocs/op delta MapClone-10 20.0 ± 0% 21.0 ± 0% +5.00% (p=0.000 n=10+10) Updates golang#58740. Change-Id: I148501e723cb2124f02045400e7ceb36af0871c8
From the developments of this proposal, i understand you people want to make the map-copy function to have built-in deep-copy support/feature to improve efficiency.. A similar discussion where myself stated the importance of such deep-copy feature happened during the reflect library proposals and a prototype for deep-copy has been generated if i am not wrong. That prototype's purpose was not restricted to in-built data-types but more of a generic template for user-defined templates as well.. Linking the Proposal discussion here, hoping it serves some importance: reflect.deepcopy() |
Is this proposal ok? |
@cuiweixie I see that you've changed the title, and now I'm not sure what the proposal is. Can you clarify? Thanks. |
change the proposal to improve map.Clone. |
Thanks. Improving |
ping |
@cuiweixie Sorry, what are you pinging? Are you asking whether it is OK for |
@ianlancetaylor: @cuiweixie posted a CL (471400) with benchmarks. |
name old time/op new time/op delta MapClone-10 65.8ms ± 7% 10.3ms ± 2% -84.30% (p=0.000 n=10+9) name old alloc/op new alloc/op delta MapClone-10 40.2MB ± 0% 40.5MB ± 0% +0.57% (p=0.000 n=10+9) name old allocs/op new allocs/op delta MapClone-10 20.0 ± 0% 23.0 ± 0% +15.00% (p=0.000 n=10+10) Updates #58740. Change-Id: I148501e723cb2124f02045400e7ceb36af0871c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/471400 Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: xie cui <523516579@qq.com> Reviewed-by: Keith Randall <khr@google.com>
CL has been merged, why not close this issue? |
Hi @cuiweixie, it looks like the commit message in the CL might have said If you want a CL to close a issue, you usually would write There are some more details in the Commit Message section of the Contribution Guide, including:
Separately -- this is a great change! 🚀 |
got it. thanks! |
name old time/op new time/op delta MapClone-10 65.8ms ± 7% 10.3ms ± 2% -84.30% (p=0.000 n=10+9) name old alloc/op new alloc/op delta MapClone-10 40.2MB ± 0% 40.5MB ± 0% +0.57% (p=0.000 n=10+9) name old allocs/op new allocs/op delta MapClone-10 20.0 ± 0% 23.0 ± 0% +15.00% (p=0.000 n=10+10) Updates golang#58740. Change-Id: I148501e723cb2124f02045400e7ceb36af0871c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/471400 Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: xie cui <523516579@qq.com> Reviewed-by: Keith Randall <khr@google.com>
name old time/op new time/op delta MapClone-10 65.8ms ± 7% 10.3ms ± 2% -84.30% (p=0.000 n=10+9) name old alloc/op new alloc/op delta MapClone-10 40.2MB ± 0% 40.5MB ± 0% +0.57% (p=0.000 n=10+9) name old allocs/op new allocs/op delta MapClone-10 20.0 ± 0% 23.0 ± 0% +15.00% (p=0.000 n=10+10) Updates golang#58740. Change-Id: I148501e723cb2124f02045400e7ceb36af0871c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/471400 Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: xie cui <523516579@qq.com> Reviewed-by: Keith Randall <khr@google.com>
in golang, we copy a map by step as follow:
map is hmap struct in runtime internally.
copy by range keys and values is inefficent.
a better way is copy map by deep copy a hmap which represent a map in runtime.
I proposal to make copy the bultin func to support copy map, and impilement it by deep copy hmap.
The text was updated successfully, but these errors were encountered: