-
Notifications
You must be signed in to change notification settings - Fork 108
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
Cleanup gRPC util funcs for timeout and percent encoding #596
Conversation
Side note, in general, I'd be happy to help figure out a workflow to get us setup with |
@mattrobenolt that'd be nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
❤️ That would be amazing, @mattrobenolt. I'm surprised there isn't a halfway decent service for this already :/ |
`strconv.AppentInt` is available in all supported Go versions, so we might as well use it!
Don't overload the zero value to signal errors. Has no performance penalty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, all of which I'm going to fix by pushing some commit's to Ed's branch. The two main issues are that:
- We're leaving a little performance on the table by allocating extra strings when encoding timeouts,
- We've undone a small performance optimization for gRPC handlers, and
- I'd prefer not to remove the error return from unit lookup.
Ed, please take a look at my commits and make sure they're okay with you.
protocol_grpc.go
Outdated
case 'H': | ||
return time.Hour | ||
default: | ||
return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API-wise, this doesn't feel like an improvement to me: we're overloading the zero value in a way that feels odd in Go, and returning an error won't measurably affect performance.
protocol_grpc.go
Outdated
size, unit = time.Hour, 'H' | ||
} | ||
value := timeout / size | ||
return strconv.FormatInt(int64(value), 10 /* base */) + string(unit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as we're golfing allocs, we can probably shave an alloc here by using strconv.AppendInt
.
protocol_grpc.go
Outdated
@@ -134,7 +109,7 @@ type grpcHandler struct { | |||
} | |||
|
|||
func (g *grpcHandler) Methods() map[string]struct{} { | |||
return grpcAllowedMethods | |||
return map[string]struct{}{http.MethodPost: {}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an extra allocation along the request path. The returned map isn't accessible to Connect users, so I think we ought to keep the code as-is.
Was there a safety concern here, or were we just trying to get rid of globals?
Pushed some extra commits to resolve all the review feedback I left. With these changes, timeout encoding drops to one allocation. |
All good with me! |
Small cleanup on gRPC util funcs. Removes timeout related init func and improves percent decoder.
Fix for timeout value length:
grpcEncodeTimeout("45s")
was45000m
but should be45000000u
. 8 char limit should only be applied to the value not the value and unit.