tonic icon indicating copy to clipboard operation
tonic copied to clipboard

Re-use Request instance?

Open ERnsTL opened this issue 3 years ago • 3 comments

Feature Request

Crates

tonic

Motivation

tonic seems slow in use-cases where many similar requests need to be sent.

Proposal

Re-use of the tonic::Request instance, just setting the payload new -- or even just overwriting some fields of the payload.

Very simple example:

        let request = tonic::Request::new(WeatherRequest{
                location: "Vienna/Austria".into()
        });

Current situation: "trait Copy not implemented for struct Request" -- "value moved in previous iteration".

Alternatives

Not sure.

ERnsTL avatar Jun 27 '21 09:06 ERnsTL

I think it's related to tokio-rs/prost/issues/429, currently Rust protobuf generator doesn't allow you to choose the pointer, in which case you're not allowed to use Arc for reusing value. I hope it can be implemented soon.

Jason5Lee avatar Jul 04 '21 00:07 Jason5Lee

http::Request is not clonable due to the Extensions type it uses. You can though construct your proto to use bytes and then use the bytes feature in prost to have the bytes field be Bytes. This then would allow you to cheaply clone the bytes and avoid heavy clones.

LucioFranco avatar Jun 07 '22 12:06 LucioFranco

Related issue https://github.com/hyperium/http/issues/395

LucioFranco avatar Jun 07 '22 12:06 LucioFranco