-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
reflect: add MapIter.Reset #46293
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This reduces the number of allocations per reflect map iteration from two to one. For golang#46293 Change-Id: Ibcff5f42fc512e637b6e460bad4518e7ac83d4c3
it := new(reflect.MapIter) it.Next() This generates a nil pointer dereference panic from reflect.Value.pointer. Generate a clearer panic. For golang#46293 Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
This allows callers to do (amortized) allocation-free iteration over many maps. Fixes golang#46293 Change-Id: I3aa6134dd00da35b508bd1e3b487332a871a3673
Change https://golang.org/cl/321891 mentions this issue: |
Change https://golang.org/cl/321890 mentions this issue: |
Change https://golang.org/cl/321889 mentions this issue: |
name old time/op new time/op delta Hash-8 12.4µs ± 0% 12.4µs ± 0% -0.33% (p=0.002 n=10+9) HashMapAcyclic-8 21.2µs ± 0% 21.3µs ± 0% +0.45% (p=0.000 n=8+8) name old alloc/op new alloc/op delta Hash-8 793B ± 0% 408B ± 0% -48.55% (p=0.000 n=10+10) HashMapAcyclic-8 128B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 9.00 ± 0% 6.00 ± 0% -33.33% (p=0.000 n=10+10) HashMapAcyclic-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Depends on golang/go#46293. Signed-off-by: Josh Bleecher Snyder <[email protected]>
This reduces the number of allocations per reflect map iteration from two to one. For golang#46293 (cherry picked from golang.org/cl/321889) Change-Id: Ibcff5f42fc512e637b6e460bad4518e7ac83d4c3
… map Value it := new(reflect.MapIter) it.Next() This generates a nil pointer dereference panic from reflect.Value.pointer. Generate a clearer panic. For golang#46293 (cherry picked from golang.org/cl/321890) Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
This allows callers to do (amortized) allocation-free iteration over many maps. Fixes golang#46293 (cherry picked from golang.org/cl/321891) Change-Id: I3aa6134dd00da35b508bd1e3b487332a871a3673
name old time/op new time/op delta Hash-8 12.4µs ± 0% 12.4µs ± 0% -0.33% (p=0.002 n=10+9) HashMapAcyclic-8 21.2µs ± 0% 21.3µs ± 0% +0.45% (p=0.000 n=8+8) name old alloc/op new alloc/op delta Hash-8 793B ± 0% 408B ± 0% -48.55% (p=0.000 n=10+10) HashMapAcyclic-8 128B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 9.00 ± 0% 6.00 ± 0% -33.33% (p=0.000 n=10+10) HashMapAcyclic-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Depends on golang/go#46293. Signed-off-by: Josh Bleecher Snyder <[email protected]>
name old time/op new time/op delta Hash-8 12.4µs ± 0% 12.4µs ± 0% -0.33% (p=0.002 n=10+9) HashMapAcyclic-8 21.2µs ± 0% 21.3µs ± 0% +0.45% (p=0.000 n=8+8) name old alloc/op new alloc/op delta Hash-8 793B ± 0% 408B ± 0% -48.55% (p=0.000 n=10+10) HashMapAcyclic-8 128B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 9.00 ± 0% 6.00 ± 0% -33.33% (p=0.000 n=10+10) HashMapAcyclic-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Depends on golang/go#46293. Signed-off-by: Josh Bleecher Snyder <[email protected]>
name old time/op new time/op delta Hash-8 12.4µs ± 0% 12.4µs ± 0% -0.33% (p=0.002 n=10+9) HashMapAcyclic-8 21.2µs ± 0% 21.3µs ± 0% +0.45% (p=0.000 n=8+8) name old alloc/op new alloc/op delta Hash-8 793B ± 0% 408B ± 0% -48.55% (p=0.000 n=10+10) HashMapAcyclic-8 128B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 9.00 ± 0% 6.00 ± 0% -33.33% (p=0.000 n=10+10) HashMapAcyclic-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Depends on golang/go#46293. Signed-off-by: Josh Bleecher Snyder <[email protected]>
name old time/op new time/op delta Hash-8 12.4µs ± 0% 12.4µs ± 0% -0.33% (p=0.002 n=10+9) HashMapAcyclic-8 21.2µs ± 0% 21.3µs ± 0% +0.45% (p=0.000 n=8+8) name old alloc/op new alloc/op delta Hash-8 793B ± 0% 408B ± 0% -48.55% (p=0.000 n=10+10) HashMapAcyclic-8 128B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 9.00 ± 0% 6.00 ± 0% -33.33% (p=0.000 n=10+10) HashMapAcyclic-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Depends on golang/go#46293. Signed-off-by: Josh Bleecher Snyder <[email protected]> Signed-off-by: Simeng He <[email protected]>
This proposal has been added to the active column of the proposals project |
Does anyone object to this proposal? |
Seems ok to me. I think there is a small issue with calling |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
This reduces the number of allocations per reflect map iteration from two to one. For golang#46293 (cherry picked from golang.org/cl/321889) Change-Id: Ibcff5f42fc512e637b6e460bad4518e7ac83d4c3
… map Value it := new(reflect.MapIter) it.Next() This generates a nil pointer dereference panic from reflect.Value.pointer. Generate a clearer panic. For golang#46293 (cherry picked from golang.org/cl/321890) Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
This allows callers to do (amortized) allocation-free iteration over many maps. Fixes golang#46293 (cherry picked from golang.org/cl/321891) Change-Id: I3aa6134dd00da35b508bd1e3b487332a871a3673
This reduces the number of allocations per reflect map iteration from two to one. For golang#46293 (cherry picked from golang.org/cl/321889) Change-Id: Ibcff5f42fc512e637b6e460bad4518e7ac83d4c3
… map Value it := new(reflect.MapIter) it.Next() This generates a nil pointer dereference panic from reflect.Value.pointer. Generate a clearer panic. For golang#46293 (cherry picked from golang.org/cl/321890) Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
This allows callers to do (amortized) allocation-free iteration over many maps. Fixes golang#46293 (cherry picked from golang.org/cl/321891) Change-Id: I3aa6134dd00da35b508bd1e3b487332a871a3673
This reduces the number of allocations per reflect map iteration from two to one. For golang#46293 (cherry picked from golang.org/cl/321889) Change-Id: Ibcff5f42fc512e637b6e460bad4518e7ac83d4c3
… map Value it := new(reflect.MapIter) it.Next() This generates a nil pointer dereference panic from reflect.Value.pointer. Generate a clearer panic. For golang#46293 (cherry picked from golang.org/cl/321890) Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
This allows callers to do (amortized) allocation-free iteration over many maps. Fixes golang#46293 (cherry picked from golang.org/cl/321891) Change-Id: I3aa6134dd00da35b508bd1e3b487332a871a3673
This reduces the number of allocations per reflect map iteration from two to one. For #46293 Change-Id: Ibcff5f42fc512e637b6e460bad4518e7ac83d4c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/321889 Trust: Josh Bleecher Snyder <[email protected]> Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Keith Randall <[email protected]>
it := new(reflect.MapIter) it.Next() This generates a nil pointer dereference panic from reflect.Value.pointer. Generate a clearer panic. For #46293 Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa Reviewed-on: https://go-review.googlesource.com/c/go/+/321890 Trust: Josh Bleecher Snyder <[email protected]> Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
Change https://go.dev/cl/400675 mentions this issue: |
This allows the caller to decide whether MapIter should be stack allocated or heap allocated based on whether it escapes. In most cases, it does not escape and thus removes the utility of MapIter.Reset (#46293). In fact, use of sync.Pool with MapIter and calling MapIter.Reset is likely to be slower. Change-Id: Ic93e7d39e5dd4c83e7fca9e0bdfbbcd70777f0e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/400675 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
Currently, iterating over a map requires two allocations: A reflect.MapIter and a runtime.hiter. By embedding a runtime.hiter (or rather, a type with the same shape and size) in a reflect.MapIter, it is possible to eliminate the second allocation. If we could re-use a reflect.MapIter to iterate over multiple maps, then we could eliminate the first allocation as well.
I propose that we add:
Allowing v to be the zero Value enables the caller to avoid pinning whatever map iter was previously iterating over.
Note that these two would be equivalent:
cc @bradfitz @randall77
The text was updated successfully, but these errors were encountered: