Search code examples
protocol-buffersscalapb

Improve Protobuf Performance using Any type


Does using the protobuf Any time improve performance? Currently, I have a couple of services that just pass data through without doing any transformations. Would using the Any type save on cpu cycles spent serializing/deserializing data?


Solution

  • Packing a message inside an Any will prevent the intermediate services that just pass it through from packing and unpacking it. Roughly speaking, if the time it takes to serialize+deserialize this message is larger than what it takes to serialize+deserialize an Any containing that message, then you may be able to save some CPU time, though I would suggest to measure first.