Skip to content

Commit 23310a8

Browse files
committedAug 3, 2018
[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
1 parent eaa18e6 commit 23310a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed
 

Diff for: ‎llvm/lib/Support/Compression.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ Error zlib::compress(StringRef InputBuffer,
6161
SmallVectorImpl<char> &CompressedBuffer,
6262
CompressionLevel Level) {
6363
unsigned long CompressedSize = ::compressBound(InputBuffer.size());
64-
CompressedBuffer.resize(CompressedSize);
64+
CompressedBuffer.reserve(CompressedSize);
6565
int CLevel = encodeZlibCompressionLevel(Level);
6666
int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize,
6767
(const Bytef *)InputBuffer.data(), InputBuffer.size(),
6868
CLevel);
6969
// Tell MemorySanitizer that zlib output buffer is fully initialized.
7070
// This avoids a false report when running LLVM with uninstrumented ZLib.
7171
__msan_unpoison(CompressedBuffer.data(), CompressedSize);
72-
CompressedBuffer.resize(CompressedSize);
72+
CompressedBuffer.set_size(CompressedSize);
7373
return Res ? createError(convertZlibCodeToString(Res)) : Error::success();
7474
}
7575

0 commit comments

Comments
 (0)
Please sign in to comment.