-
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 Value.SetZero #52376
Comments
CC @randall77 |
Seems fine to me. |
@dsnet Are you going to try to tackle this for 1.19? |
|
I have an implementation ready, but this needs to go through the proposal process. There is no guarantee that this gets accepted. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This proposal has been added to the active column of the proposals project |
Change https://go.dev/cl/411476 mentions this issue: |
Given that #33136 has been around since Go1.16, I'm fairly sure I'm accounting from the benefits of that optimization. In https://go.dev/cl/411476, the performance numbers are as follows:
where:
we can see that |
Thanks for the numbers. This seems fine now that we understand the justification well. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
This is a re-proposal of #33136, which was converted into a performance optimization where
reflect.Zero
does not allocate. That change certainly helps, but is insufficient especially when trying to zero out small values.I propose we add a dedicated
Value.SetZero
method.A prototype implementation of mine shows that this is much faster for small values:
Unfortunately, there is no convenient
SetXXX
API for clearing nil-able types (e.g., pointers, slices, and maps) and I was going to propose aValue.SetNil
method, but we might as well expand that handle clearing all kinds.The text was updated successfully, but these errors were encountered: