By default, gRPC uses Protobuf parser 
<https://github.com/grpc/grpc-java/blob/f0512db060ac5582547a4e4ebd5f3bd2c568d721/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java#L223>
 
for decoding data. You can definitely implement your own marshaller and do 
it yourself (see the Json serialization example 
<https://github.com/grpc/grpc-java/tree/master/examples/src/main/java/io/grpc/examples/advanced>).
 
However, that's mostly for choosing to use a different format of 
serialization and probably won't make the problem of creating temp objects 
better. As most of them happen in deframing messages 
<https://github.com/grpc/grpc-java/blob/f0512db060ac5582547a4e4ebd5f3bd2c568d721/core/src/main/java/io/grpc/internal/MessageDeframer.java#L165>,
 
that's the part you do not have control for. There had been work 
<https://github.com/grpc/grpc-java/pull/7375> for making some improvement, 
but I believe most of them weren't be having significant impact on garbage 
collection. That's said, there probably isn't much can be done in terms of 
improving GC pressure.

On the other hand, the existing Protobuf marshaller does have something can 
be improved, which is making an extra copy 
<https://github.com/grpc/grpc-java/blob/f0512db060ac5582547a4e4ebd5f3bd2c568d721/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java#L188>
 
of received bytes before handing them over to Protobuf parser (but it does 
reuse 
the byte array 
<https://github.com/grpc/grpc-java/blob/f0512db060ac5582547a4e4ebd5f3bd2c568d721/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java#L120>
 
to avoid excessive amount of allocation and GC). There had been attempts 
<https://github.com/grpc/grpc-java/pull/7330> to eliminate this copy, but 
it turned out requiring changes in Protobuf or JDK to make the gain larger 
than the extra cost. There's continued effort on that path. That's being 
said, if you are going to implement your own marshaller, you may be able to 
eliminate this copy.
On Thursday, March 18, 2021 at 10:41:47 AM UTC-7 [email protected] wrote:

> Hi,
> I am new to GRPC and using it in JAVA. when I use the generate client 
> stub, it creates lot of temp object which need to be garbage collected. 
> This can potentially create a lot of Garbage Collection pressure for high 
> throughput java applications. To work around this issue, I want to get an 
> handle on to the underlying byte buffer and decode the data myself. Is that 
> possible? If so, can I get some pointers to go about this.
>
> Thank You
> Smruti
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/480a98d3-08b6-4deb-be91-98323f78a486n%40googlegroups.com.

Reply via email to