The current encoding process generates a large amount of memory allocation, and the GC pressure will increase when the QPS becomes large. Consider reducing the number of memory allocations to optimize the encoding process.
Here is my proposal:
Modify the BinaryEncoderinterface definition
type BinaryEncoder interface {
Encode(s *Stream)
}
Reduce NewBuffercalls by stitching each field encoding result directly through Stream. the Streamdefinition is as follows:
The current encoding process generates a large amount of memory allocation, and the GC pressure will increase when the QPS becomes large. Consider reducing the number of memory allocations to optimize the encoding process.
Here is my proposal:
Modify the
BinaryEncoder
interface definitionReduce
NewBuffer
calls by stitching each field encoding result directly throughStream
. theStream
definition is as follows:Stream
implements theWriteXxx
method from the originalBuffer
.The
Encode
methods of all types that implement theBinaryEncoder
interface require only minor modifications, such asDataValue
:For detailed implementation, please refer to https://github.com/gopcua/opcua/pull/726