From 270bdf132f31392bb0e816672250cde029a1baae Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Fri, 3 Jan 2025 14:34:03 +0800 Subject: [PATCH] [Enhancement] Remove unnecessary frequent memory alloc and release requests (#54604) Signed-off-by: sevev --- be/src/storage/persistent_index.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/be/src/storage/persistent_index.cpp b/be/src/storage/persistent_index.cpp index f5679144b360f..388731b461730 100644 --- a/be/src/storage/persistent_index.cpp +++ b/be/src/storage/persistent_index.cpp @@ -233,11 +233,11 @@ Status ImmutableIndexShard::compress_and_write(const CompressionTypePB& compress const BlockCompressionCodec* codec = nullptr; RETURN_IF_ERROR(get_block_compression_codec(compression_type, &codec)); int32_t offset = 0; + faststring compressed_body; for (int32_t i = 0; i < npage(); i++) { + compressed_body.resize(codec->max_compressed_len(_page_size)); Slice input((uint8_t*)_pages.data() + i * _page_size, _page_size); *uncompressed_size += input.get_size(); - faststring compressed_body; - compressed_body.resize(codec->max_compressed_len(_page_size)); Slice compressed_slice(compressed_body); RETURN_IF_ERROR(codec->compress(input, &compressed_slice)); RETURN_IF_ERROR(wb.append(compressed_slice));