OSDN Git Service

[PDB] Serialize records into a stack-allocated buffer.
authorZachary Turner <zturner@google.com>
Mon, 21 Aug 2017 20:17:19 +0000 (20:17 +0000)
committerZachary Turner <zturner@google.com>
Mon, 21 Aug 2017 20:17:19 +0000 (20:17 +0000)
We were using a std::vector<> and resizing to MaxRecordLength,
which is ~64KB.  We would then do this repeatedly often many
times in a tight loop, which was causing measurable performance
impact when linking PDBs.

Patch by Alex Telishev
Differential Revision: https://reviews.llvm.org/D36940

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311375 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/CodeView/SymbolSerializer.h
lib/DebugInfo/CodeView/SymbolSerializer.cpp

index b63ced5..f4d8ab0 100644 (file)
@@ -28,7 +28,10 @@ namespace codeview {
 
 class SymbolSerializer : public SymbolVisitorCallbacks {
   BumpPtrAllocator &Storage;
-  std::vector<uint8_t> RecordBuffer;
+  // Since this is a fixed size buffer, use a stack allocated buffer.  This
+  // yields measurable performance increase over the repeated heap allocations
+  // when serializing many independent records via writeOneSymbol.
+  std::array<uint8_t, MaxRecordLength> RecordBuffer;
   MutableBinaryByteStream Stream;
   BinaryStreamWriter Writer;
   SymbolRecordMapping Mapping;
index 9a2e776..0071ecc 100644 (file)
@@ -21,8 +21,7 @@ using namespace llvm::codeview;
 
 SymbolSerializer::SymbolSerializer(BumpPtrAllocator &Allocator,
                                    CodeViewContainer Container)
-    : Storage(Allocator), RecordBuffer(MaxRecordLength),
-      Stream(RecordBuffer, support::little), Writer(Stream),
+    : Storage(Allocator), Stream(RecordBuffer, support::little), Writer(Stream),
       Mapping(Writer, Container) {}
 
 Error SymbolSerializer::visitSymbolBegin(CVSymbol &Record) {