[PATCH] D93761: [libObject/Decompressor] - Speedup Decompressor::resizeAndDecompress() method.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 23 07:01:48 PST 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
grimar requested review of this revision.
Herald added a project: LLVM.

I've debugged the code that tries to decompress a large
chunk of data. In my case the size of decompressed data was expected
to be ~4GB.

I've found that the following code

  SmallString<0> Out;
  ...
  Out.resize(DecompressedSize);

takes too long. Instead of `resize` we can use the `resize_for_overwrite` here.

In `Debug` configuration `Out.resize(0xffffffff)` call takes 44,1s,
while `Out.resize_for_overwrite(0xffffffff)` takes 10.8s for me. I.e. speedup is ~4.08x.

For `Release` configuration the numbers are:
`resize_for_overwrite` takes ~1700 microseconds, `resize` takes ~1850000 microseconds.
I.e. the new version is ~1088x times faster.


https://reviews.llvm.org/D93761

Files:
  llvm/include/llvm/Object/Decompressor.h


Index: llvm/include/llvm/Object/Decompressor.h
===================================================================
--- llvm/include/llvm/Object/Decompressor.h
+++ llvm/include/llvm/Object/Decompressor.h
@@ -30,7 +30,7 @@
   /// Resize the buffer and uncompress section data into it.
   /// @param Out         Destination buffer.
   template <class T> Error resizeAndDecompress(T &Out) {
-    Out.resize(DecompressedSize);
+    Out.resize_for_overwrite(DecompressedSize);
     return decompress({Out.data(), (size_t)DecompressedSize});
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93761.313549.patch
Type: text/x-patch
Size: 542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201223/3b36eae2/attachment.bin>


More information about the llvm-commits mailing list