-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Wasted proto.Clone
in http2Server.WriteStatus
#2182
Comments
I think we could move some of the implementation of |
Would it make sense to add the following two methods to func (s *Status) MarshalledProto() ([]byte, err) {...}
func (s *Status) HasDetails() bool {...} And |
That technically works but it complicates the API for something that external users probably won't ever want. Another trick we could play: package internal;
var StatusRawProto func(*status.Status) *spb.Status
---
package status;
func init() {
internal.StatusRawProto = func(s *Status) *spb.Status { return s.s }
}
---
package transport;
...
if p := internal.StatusRawProto(st); p != nil && len(p.Details) > 0 {
... |
Thanks. Makes sense. But, what is the advantage (or need) of defining |
It can't be implemented in |
I tried making the following changes: package internal;
var StatusRawProto interface{} // func (*status.Status) *spb.Status
---
package status;
func init() {
internal.StatusRawProto = statusRawProto
}
func statusRawProto(s *Status) *spb.Status { return s.s }
---
package transport;
...
srp := internal.StatusRawProto.(func(*status.Status) *spb.Status)
if p := srp(st); p != nil && len(p.Details) > 0 {
... I see that a couple of tests which do a I did a Does this mean that we cannot avoid a Thanks. |
The tests should be fixed - they were just getting lucky before. It's incorrect to compare protos with a |
I added a helper in Would you be OK to add the helper to the // this will be useful when we have a Status object, or if we want to use cmp.Equal() at some point
func (s *Status) Equal(other *Status) bool {...}
// this is for errors generated from Status
func ErrEqual(err1, err2 error) bool {...} |
I'm OK with something like that, but only if it's critical for some use cases or is something many people will want to use as a convenience, since it clutters the API. How about let's leave it out for now, re-implement the equality checking in |
grpc-go/transport/http2_server.go
Line 773 in 7268ca4
Most of the time, there is no detail in the status.
In our application, the
proto.Clone
itself takes about2%
of total CPU time.It can be avoided if we add a method
HasDetail
inStatus
.The text was updated successfully, but these errors were encountered: