From f993b2913bf7f6d367600c7a28824818ff8e44b9 Mon Sep 17 00:00:00 2001 From: congqixia Date: Mon, 17 Jun 2024 12:06:04 +0800 Subject: [PATCH] enhance: Reserve space of payload writer when serialize data (#33817) See also #33561 #33562 Signed-off-by: Congqi Xia --- internal/storage/data_codec.go | 1 + internal/storage/payload.go | 1 + internal/storage/payload_writer.go | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/internal/storage/data_codec.go b/internal/storage/data_codec.go index 59f2b89ad451..e578c3ec5320 100644 --- a/internal/storage/data_codec.go +++ b/internal/storage/data_codec.go @@ -290,6 +290,7 @@ func (insertCodec *InsertCodec) Serialize(partitionID UniqueID, segmentID Unique return nil, err } eventWriter.SetEventTimestamp(startTs, endTs) + eventWriter.Reserve(int(rowNum)) var memorySize int64 for _, block := range data { diff --git a/internal/storage/payload.go b/internal/storage/payload.go index 99fa0f52094e..683b91b4014c 100644 --- a/internal/storage/payload.go +++ b/internal/storage/payload.go @@ -47,6 +47,7 @@ type PayloadWriterInterface interface { GetPayloadBufferFromWriter() ([]byte, error) GetPayloadLengthFromWriter() (int, error) ReleasePayloadWriter() + Reserve(size int) Close() } diff --git a/internal/storage/payload_writer.go b/internal/storage/payload_writer.go index 819b20b1b465..b8b3c68f23b4 100644 --- a/internal/storage/payload_writer.go +++ b/internal/storage/payload_writer.go @@ -535,6 +535,10 @@ func (w *NativePayloadWriter) FinishPayloadWriter() error { ) } +func (w *NativePayloadWriter) Reserve(size int) { + w.builder.Reserve(size) +} + func (w *NativePayloadWriter) GetPayloadBufferFromWriter() ([]byte, error) { data := w.output.Bytes()