-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: reflect: add alloc-free way retrieve value from Value #46093
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
Can't you do:
|
Hmmmm. In toy benchmarks, yes. In my larger benchmark, no. Possibly user error; I'll report back. |
Ah. With the reflect.ValueOf.Elem.Set approach, I'm ending up with |
This panics: var v reflect.Value = ...
a := new([32]byte)
reflect.ValueOf(a).Set(v) I may be holding it wrong, but I don't see how to use |
Seems to work. |
Thanks, Keith. I'm experimenting a bit here still. I'll report back. |
Is this a duplicate of #46131 now? |
This proposal has been added to the active column of the proposals project |
I don't think they're dups. But I'm curious what problem @josharian hit with @randall77's latest comment. |
Something non-obvious happening. Still in my queue. Thought was going to be today, probably tomorrow. |
I wasn't taking sufficient care that my values didn't escape. I finally got this working as anticipated. Thanks, Keith, and sorry about the noise. |
No change in consensus, so declined. |
It is currently impossible to retrieve large values (e.g.
[32]byte
) from a reflect.Value without allocating. There are specialized getters for common types (Value.Int
,Value.Bytes
, etc.), but nothing general purpose.I propose that we add a new API that lets the caller bring their own storage. Something like this:
Then the caller can do:
This call pattern might not work out of the gate, since the argument to Value.Store will escape. We might be able to fix that with appropriate annotations and/or toolchain support.
But even if not, the caller could use a sync.Pool of
*[32]byte
. The key thing is that the allocation is moved to the caller's side.We'd need a Value.CanStore too, unless we are comfortable re-using Value.CanInterface for it.
The text was updated successfully, but these errors were encountered: