reflect: allow stack allocation of underlying value for reflect.Value.Interface #71349
Labels
BugReport
Issues describing a possible bug in the Go implementation.
compiler/runtime
Issues related to the Go compiler and/or runtime.
Go version
tip
What did you do?
Run this simple test (playground link):
What did you see happen?
What did you expect to see?
Ideally, zero heap allocations in this test, and ideally reflect.Value.Interface would allow the underlying value to not always be heap allocated. This affects the fmt package and can affect other users of reflect like serialization libraries. This issue is a spin out from #8618 (comment).
There are currently two reasons the underlying value escapes to the heap:
I sent https://go.dev/cl/528535 to hopefully address the first reason in reflect.packEface.
For addressing the second reason above and handling method values, I sent:
for reflect.methodValueCall so that a stack-based methodValue can be tracked, including for example to properly update pointers during a stack copy operation.
Together, these changes allow the test to pass without heap allocations.
I am hopefully returning to this shortly, and filing this issue to re-summarize the approach and to help with tracking & discussion. (Previously, a short overview was in #8618 (comment), in addition to more details in the individual CLs).
The text was updated successfully, but these errors were encountered: