gRPC Serialization Trait and grpc::Slice.

Skip to first unread message

Waqas Alam

Jun 17, 2022, 1:58:14 AMJun 17
I'm using C++ gRPC Serialization Trait to encode gRPC messages using zero copy in gRPC unary API. Each message has a vector of buffers where each buffer is passed to grpc::Slice and there is no need to copy the buffer. I was wondering if there is something interesting I can do on the receive side ? What I have observed is that gRPC doesn't keep any state for the slices and data is received in chunks of size 8192 which is GRPC_TCP_DEFAULT_READ_SLICE_SIZE.  The issue I have is if total size of the all the buffers in a message is greater than 8192 a buffer may overlap two or more slices. This can happen for subsequent slices as well so currently I have to copy all the slices into a single slice or copy the buffer which extends over multiple slices. If there was a way to limit number of buffers to a single slice they can share the underneath  memory of a single slice and also avoid the copy operation. Just curious if current gRPC API provides such a capability.  


Mark D. Roth

Jun 22, 2022, 1:52:18 PMJun 22
to Waqas Alam,
Unfortunately, we don't currently have any support for this kind of zero-copy read on the receiving side.  In the long run, we have some ideas about how we'd like to support this kind of thing, but we haven't had time to turn our attention to this yet, so we have no concrete plan or ETA yet.  But I would expect that we will eventually add some APIs to support this kind of thing.

Note that gRPC does not provide any guarantee that received messages will show up in any particular chunk size.  You may happen to be seeing 8192 bytes right now, but that's highly dependent upon the server application, the network, proxies, encryption software, and a bunch of other factors, so what you're seeing right now could change at any time.

You received this message because you are subscribed to the Google Groups "" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Mark D. Roth <>
Software Engineer
Google, Inc.
Reply all
Reply to author
0 new messages