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

pkg/proto: adopt CodecV2 and gRPC buffer pooling #2070

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jzelinskie
Copy link
Member

@jzelinskie jzelinskie commented Sep 18, 2024

This replaces our existing gRPC codec (which enabled us to use vtprotobuf) with the new v2 codec interface that can support buffer pooling.

Huge thanks to engineers from Google and LinkedIn for fleshing out this work and upstreaming the necessary changes. There was a great talk from gRPConf I can share once it's uploaded to YouTube.

I did regenerate our go.mod which combined all of the indirect dependencies into one block. If there were purposely split out, I can fix it.

See the sister PR to this introducing the Codec for Vitess: vitessio/vitess#16790

@jzelinskie jzelinskie requested a review from a team as a code owner September 18, 2024 20:25
@github-actions github-actions bot added the area/dependencies Affects dependencies label Sep 18, 2024
Copy link
Contributor

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

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

See comment; I'll let someone more familiar with the internals give an approval.

pool.Put(buf)
return nil, err
}
return mem.BufferSlice{mem.NewBuffer(buf, pool)}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious - what does NewBuffer do here? Haven't we already reserved the relevant memory in the pool.Get call above?

Alternatively, is there some reading about how this approach works generally?

Copy link
Member Author

Choose a reason for hiding this comment

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

By and large, this code is inspired by the upstream default codec: https://github.com/grpc/grpc-go/blob/v1.66.2/encoding/proto/proto.go

mem.NewBuffer is less about allocating bytes and more about tracking the lifetime and ownership of the buffer: https://github.com/grpc/grpc-go/blob/v1.66.2/mem/buffers.go#L83-L102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependencies Affects dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants