<div dir="ltr">I don't think this is what Eli was suggesting.<br><br>set_size should be used instead of resize/reserve here - it acts like resize, but doesn't initialize the data. Using only 'reserve' violates the SmallVector contract - because data is then written beyond the 'size'.<br><br>Instead, use 'set_size' before the compression, and resize down to the final size after the compressed bytes have been written.<br><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 3, 2018 at 12:38 PM Fangrui Song via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: maskray<br>
Date: Fri Aug  3 12:37:49 2018<br>
New Revision: 338913<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=338913&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=338913&view=rev</a><br>
Log:<br>
[Support] Don't initialize compressed buffer allocated by zlib::compress<br>
<br>
resize() (zeroing) makes every allocated page resident. The actual size of the compressed buffer is usually much<br>
smaller. Making every page resident is wasteful.<br>
<br>
When linking a test binary with ~1.9GiB uncompressed debug info with LLD, this optimization decreases max RSS by ~1.5GiB.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/50223" rel="noreferrer" target="_blank">https://reviews.llvm.org/50223</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/Support/Compression.cpp<br>
<br>
Modified: llvm/trunk/lib/Support/Compression.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Compression.cpp?rev=338913&r1=338912&r2=338913&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Compression.cpp?rev=338913&r1=338912&r2=338913&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Compression.cpp (original)<br>
+++ llvm/trunk/lib/Support/Compression.cpp Fri Aug  3 12:37:49 2018<br>
@@ -61,7 +61,7 @@ Error zlib::compress(StringRef InputBuff<br>
                      SmallVectorImpl<char> &CompressedBuffer,<br>
                      CompressionLevel Level) {<br>
   unsigned long CompressedSize = ::compressBound(InputBuffer.size());<br>
-  CompressedBuffer.resize(CompressedSize);<br>
+  CompressedBuffer.reserve(CompressedSize);<br>
   int CLevel = encodeZlibCompressionLevel(Level);<br>
   int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize,<br>
                         (const Bytef *)InputBuffer.data(), InputBuffer.size(),<br>
@@ -69,7 +69,7 @@ Error zlib::compress(StringRef InputBuff<br>
   // Tell MemorySanitizer that zlib output buffer is fully initialized.<br>
   // This avoids a false report when running LLVM with uninstrumented ZLib.<br>
   __msan_unpoison(CompressedBuffer.data(), CompressedSize);<br>
-  CompressedBuffer.resize(CompressedSize);<br>
+  CompressedBuffer.set_size(CompressedSize);<br>
   return Res ? createError(convertZlibCodeToString(Res)) : Error::success();<br>
 }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>