Skip to content
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

transport: remove decodeState from server to reduce allocations #4423

Merged
merged 6 commits into from May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 6 additions & 20 deletions internal/transport/http2_server.go
Expand Up @@ -360,20 +360,6 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
if timeout, err = decodeTimeout(hf.Value); err != nil {
headerError = true
}
case "grpc-tags-bin":
v, err := decodeBinHeader(hf.Value)
if err != nil {
headerError = true
return
}
mdata[hf.Name] = append(mdata[hf.Name], string(v))
case "grpc-trace-bin":
v, err := decodeBinHeader(hf.Value)
if err != nil {
headerError = true
return
}
mdata[hf.Name] = append(mdata[hf.Name], string(v))
default:
if isReservedHeader(hf.Name) && !isWhitelistedHeader(hf.Name) {
break
Expand Down Expand Up @@ -418,12 +404,12 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
// Attach the received metadata to the context.
if len(mdata) > 0 {
s.ctx = metadata.NewIncomingContext(s.ctx, mdata)
}
if statsTags, ok := mdata["grpc-tags-bin"]; ok && len(statsTags) > 0 {
s.ctx = stats.SetIncomingTags(s.ctx, []byte(statsTags[0]))
}
if statsTrace, ok := mdata["grpc-trace-bin"]; ok && len(statsTrace) > 0 {
s.ctx = stats.SetIncomingTrace(s.ctx, []byte(statsTrace[0]))
if statsTags := mdata["grpc-tags-bin"]; len(statsTags) > 0 {
s.ctx = stats.SetIncomingTags(s.ctx, []byte(statsTags[len(statsTags)-1]))
}
if statsTrace := mdata["grpc-trace-bin"]; len(statsTrace) > 0 {
s.ctx = stats.SetIncomingTrace(s.ctx, []byte(statsTrace[0]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing re: 0 -> len(statsTrace)-1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

}
}
t.mu.Lock()
if t.state != reachable {
Expand Down
7 changes: 2 additions & 5 deletions internal/transport/transport_test.go
Expand Up @@ -2077,11 +2077,8 @@ func (s) TestClientDecodeHeaderStatusErr(t *testing.T) {

got := ts.status
want := test.wantStatus
if got.Code() != want.Code() {
t.Fatalf("operateHeaders() got code %d, want %d", got.Code(), want.Code())
}
if got.Message() != want.Message() {
t.Fatalf("operateHeaders() got message %s, want %s", got.Message(), want.Message())
if got.Code() != want.Code() || got.Message() != want.Message() {
t.Fatalf("operateHeaders(%v); status = %v; want %v", test.metaHeaderFrame, got, want)
}
})
}
Expand Down