Skip to content

Commit

Permalink
[Support] Don't initialize compressed buffer allocated by zlib::compress
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaskRay committed Aug 3, 2018
1 parent eaa18e6 commit 23310a8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Support/Compression.cpp
Expand Up @@ -61,15 +61,15 @@ Error zlib::compress(StringRef InputBuffer,
SmallVectorImpl<char> &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(),
CLevel);
// 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();
}

Expand Down

0 comments on commit 23310a8

Please sign in to comment.