Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Optimize `ProtoBufSerializationProvider` by minimizing copying #943
Current implementation of
Less copying during protobuf serialization/deserialization leads to
Motivation: Current implementation of `ProtoBufSerializationProvider` has a few performance issues: 1. `ProtoDeserializer` may create an intermediate copy of composite buffers and then copy it again inside proto parser. 2. `DefaultSerializer.DEFAULT_SIZE_ESTIMATOR` inaccurately predicts size for destination `Buffer`. For aggregated API we may use `getSerializedSize()` to allocate enough bytes for destination `Buffer`. 3. `MessageLite.writeTo(OutputStream)` creates internal copy of data that could be avoided if we create `CodedOutputStream` from internal data storage of destination `Buffer`. Modifications: - Create optimized version of `CodedInputStream` for `ProtoDeserializer` to do less copying during proto deserialization; - Provide number of `bytesEstimate` for serialization for aggregated API; - Create optimized version of `CodedOutputStream` for `ProtoSerializer` to do less copying during proto serialization; Results: Less copying during protobuf serialization/deserialization leads to improved throughput by 5-15% on the gRPC client and server when they (de)serialize 16Kb payload body.