-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
proto: document whether custom proto.Unmarshaler should Reset or not #424
Comments
Yep, the current comment is just plain wrong. (I think @randall77 has a patch that updates the comment as part of a much larger refactoring. He or @cherrymui may have more information on when that's likely to land.) |
Yes, @randall77's patch fixes the comment. @dsnet is working on the landing. |
I'm trying to get this work landing in the git repo in the near term, next week or two. but it will land in a separate branch, and will have to sit there for some time. The new implementation causes much chaos in tests because of brittle tests using |
Thank you for keeping us in the loop :) It would be great if we could not pull in another dependency though. |
The dev branch already has the updated comments. It's unfortunate that we are changing the semantics, but the only sane behavior is for messages not to reset themselves, otherwise it is impossible for UnmarshalMerge to work properly. |
The proto.Unmarshaler interface expects the generated Unmarshal method to call Reset, as stated in the documentation here https://github.com/golang/protobuf/blob/master/proto/decode.go#L380-L387
If we look at the code at
https://github.com/golang/protobuf/blob/master/proto/decode.go#L407-L422
We see that this will cause Reset to be called twice, which I suspect will result in two allocations, instead of one. When you are generating an Unmarshal method, this type of thing really impacts performance.
We can also see from this code that this will mess up the implementation of UnmarshalMerge, as the results will not be unmarshaling will not be merged if Reset is called in the generated Unmarshal method.
I propose we update the comment to not expect the generated Unmarshal method to call Reset.
The text was updated successfully, but these errors were encountered: