grpc-go
grpc-go copied to clipboard
Add NewUnary to ClientConnInterface to reduce memory during long unary requests
Please see the FAQ in our main README.md before submitting your issue.
Use case(s) - what problem will this feature solve?
If a unary request takes a long time, we hold on to the memory until the response is received. If we use a unary-stream, we can reset the request object to release the memory before blocking for the response, but we cannot do this for unary because Invoke only returns after the response is received.
Proposed Solution
Even if we wanted to modify the generated grpc services, we don't have an option to just return the ClientStream object. I think it would be easiest to add a NewUnary function to call.go.
func (cc *ClientConn) NewUnary(ctx context.Context, method string, args, reply any, opts ...CallOption) (ClientStream, error) {
opts = combine(cc.dopts.callOptions, opts)
if cc.dopts.unaryInt != nil {
return cc.dopts.unaryInt(ctx, method, args, reply, cc, invoke, opts...)
}
return newClientStream(ctx, unaryStreamDesc, cc, method, opts...)
}
This will allow us to change the generated unary code to be similar to unary-stream.