From 23310a89be17e44babd54650d76ef1a236b8a879 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 3 Aug 2018 19:37:49 +0000 Subject: [PATCH] [Support] Don't initialize compressed buffer allocated by zlib::compress resize() (zeroing) makes every allocated page resident. The actual size of the compressed buffer is usually much smaller. Making every page resident is wasteful. When linking a test binary with ~1.9GiB uncompressed debug info with LLD, this optimization decreases max RSS by ~1.5GiB. Differential Revision: https://reviews.llvm.org/50223 llvm-svn: 338913 --- llvm/lib/Support/Compression.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp index c279d10f6c61..05bd7b58e08b 100644 --- a/llvm/lib/Support/Compression.cpp +++ b/llvm/lib/Support/Compression.cpp @@ -61,7 +61,7 @@ Error zlib::compress(StringRef InputBuffer, SmallVectorImpl &CompressedBuffer, CompressionLevel Level) { unsigned long CompressedSize = ::compressBound(InputBuffer.size()); - CompressedBuffer.resize(CompressedSize); + CompressedBuffer.reserve(CompressedSize); int CLevel = encodeZlibCompressionLevel(Level); int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize, (const Bytef *)InputBuffer.data(), InputBuffer.size(), @@ -69,7 +69,7 @@ Error zlib::compress(StringRef InputBuffer, // Tell MemorySanitizer that zlib output buffer is fully initialized. // This avoids a false report when running LLVM with uninstrumented ZLib. __msan_unpoison(CompressedBuffer.data(), CompressedSize); - CompressedBuffer.resize(CompressedSize); + CompressedBuffer.set_size(CompressedSize); return Res ? createError(convertZlibCodeToString(Res)) : Error::success(); }