From af04423e312139ea7181464cce2ed68e48b475dc Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 21 Aug 2017 20:17:19 +0000 Subject: [PATCH] [PDB] Serialize records into a stack-allocated buffer. 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 | 5 ++++- lib/DebugInfo/CodeView/SymbolSerializer.cpp | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/llvm/DebugInfo/CodeView/SymbolSerializer.h b/include/llvm/DebugInfo/CodeView/SymbolSerializer.h index b63ced5217b..f4d8ab0c3c2 100644 --- a/include/llvm/DebugInfo/CodeView/SymbolSerializer.h +++ b/include/llvm/DebugInfo/CodeView/SymbolSerializer.h @@ -28,7 +28,10 @@ namespace codeview { class SymbolSerializer : public SymbolVisitorCallbacks { BumpPtrAllocator &Storage; - std::vector 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 RecordBuffer; MutableBinaryByteStream Stream; BinaryStreamWriter Writer; SymbolRecordMapping Mapping; diff --git a/lib/DebugInfo/CodeView/SymbolSerializer.cpp b/lib/DebugInfo/CodeView/SymbolSerializer.cpp index 9a2e776feb7..0071ecc8568 100644 --- a/lib/DebugInfo/CodeView/SymbolSerializer.cpp +++ b/lib/DebugInfo/CodeView/SymbolSerializer.cpp @@ -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) { -- 2.50.1