-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: Type.Field allocates #2320
Comments
Owner changed to builder@golang.org. |
http://golang.org/cl/5564066 Owner changed to @bradfitz. Status changed to Started. |
Also, Russ's earlier version with read-only memory: http://golang.org/cl/5371098 Pushing out past Go1. No super compelling argument for it. Labels changed: added priority-later, removed priority-go1. Owner changed to builder@golang.org. |
Per discussion on https://golang.org/cl/5371098, we've decided the drawbacks outweigh the benefits. If the pendulum ever swings back, the CL is there. Status changed to WorkingAsIntended. |
Just want to leave a comment on this. This makes up about a third of the allocations for my team's encoder and decoder and has a major impact on performance. I looked into alternative strategies to solve this in type.go, but concluded that it isn't possible to have a satisfying solution so long as the index field is a slice and wanted to leave a note. It isn't possible to back the slice by the stack (say by an unexposed array in the struct) because escape analysis (correctly) will detect that due to the return, the backing array of the slice must be on the heap. Once the slice must be backed by the heap, the only way to reduce allocations is to reduce the number of them. This isn't possible because we would either back the slice by constants (which breaks the semantics of being able to modify the returned value) or back it by an array that is shared across method calls (which is bad for a number of reasons). |
Backing the slice with an unexported array in the struct won't work,
|
Use assembler to make runtime.staticuint64s into a readonly array so that the reflect package can safely create a slice without requiring any allocation. Fixes #2320 Fixes #68380 Change-Id: If2c97238eca782d0632db265c840581d4ecb9d18 Reviewed-on: https://go-review.googlesource.com/c/go/+/597855 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
The text was updated successfully, but these errors were encountered: