From 36515e45642f7f9363257f123279f84090b0069a Mon Sep 17 00:00:00 2001 From: xiezhengyao Date: Fri, 24 May 2024 15:08:54 +0800 Subject: [PATCH] perf: nocopy read binary --- pkg/protocol/bthrift/binary.go | 5 ++--- pkg/remote/codec/thrift/binary_protocol.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/protocol/bthrift/binary.go b/pkg/protocol/bthrift/binary.go index 2b5dbf3aa8..d71bac9e04 100644 --- a/pkg/protocol/bthrift/binary.go +++ b/pkg/protocol/bthrift/binary.go @@ -467,8 +467,7 @@ func (binaryProtocol) ReadString(buf []byte) (value string, length int, err erro if size < 0 || int(size) > len(buf) { return value, length, perrors.NewProtocolErrorWithType(thrift.INVALID_DATA, "[ReadString] the string size greater than buf length") } - data := spanCache.Copy(buf[length : length+int(size)]) - value = utils.SliceByteToString(data) + value = utils.SliceByteToString(buf[length : length+int(size)]) length += int(size) return } @@ -484,7 +483,7 @@ func (binaryProtocol) ReadBinary(buf []byte) (value []byte, length int, err erro if size < 0 || size > len(buf) { return value, length, perrors.NewProtocolErrorWithType(thrift.INVALID_DATA, "[ReadBinary] the binary size greater than buf length") } - value = spanCache.Copy(buf[length : length+size]) + value = buf[length : length+size] length += size return } diff --git a/pkg/remote/codec/thrift/binary_protocol.go b/pkg/remote/codec/thrift/binary_protocol.go index fadffbbdb5..fc901d0be0 100644 --- a/pkg/remote/codec/thrift/binary_protocol.go +++ b/pkg/remote/codec/thrift/binary_protocol.go @@ -509,7 +509,7 @@ func (p *BinaryProtocol) ByteBuffer() remote.ByteBuffer { // next ... func (p *BinaryProtocol) next(size int) ([]byte, error) { - buf, err := p.trans.Next(size) + buf, err := p.trans.ReadBinary(size) if err != nil { return buf, perrors.NewProtocolError(err) }