[CodeView] Reserve TypeDatabase records up front.
Most of the time we know exactly how many type records we
have in a list, and we want to use the visitor to deserialize
them into actual records in a database. Previously we were
just using push_back() every time without reserving the space
up front in the vector. This is obviously terrible from a
performance standpoint, and it's not uncommon to have PDB
files with half a million type records, where the performance
degredation was quite noticeable.
llvm-svn: 302302
diff --git a/llvm/tools/llvm-pdbdump/Analyze.cpp b/llvm/tools/llvm-pdbdump/Analyze.cpp
index b65dd40..f7d6ec5 100644
--- a/llvm/tools/llvm-pdbdump/Analyze.cpp
+++ b/llvm/tools/llvm-pdbdump/Analyze.cpp
@@ -74,7 +74,7 @@
if (!Tpi)
return Tpi.takeError();
- TypeDatabase TypeDB;
+ TypeDatabase TypeDB(Tpi->getNumTypeRecords());
TypeDatabaseVisitor DBV(TypeDB);
TypeDeserializer Deserializer;
TypeVisitorCallbackPipeline Pipeline;
diff --git a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
index ca7efa6..2dd4ef0 100644
--- a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
@@ -631,7 +631,7 @@
Visitors.push_back(make_unique<TypeDeserializer>());
if (!StreamDB.hasValue()) {
- StreamDB.emplace();
+ StreamDB.emplace(Tpi->getNumTypeRecords());
Visitors.push_back(make_unique<TypeDatabaseVisitor>(*StreamDB));
}
// If we're in dump mode, add a dumper with the appropriate detail level.
@@ -722,14 +722,14 @@
if (DB.hasValue())
return Error::success();
- DB.emplace();
-
auto Tpi =
(SN == StreamTPI) ? File.getPDBTpiStream() : File.getPDBIpiStream();
if (!Tpi)
return Tpi.takeError();
+ DB.emplace(Tpi->getNumTypeRecords());
+
TypeVisitorCallbackPipeline Pipeline;
TypeDeserializer Deserializer;
TypeDatabaseVisitor DBV(*DB);
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 0438687..3f4b6c7 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -70,7 +70,7 @@
public:
friend class COFFObjectDumpDelegate;
COFFDumper(const llvm::object::COFFObjectFile *Obj, ScopedPrinter &Writer)
- : ObjDumper(Writer), Obj(Obj), Writer(Writer) {}
+ : ObjDumper(Writer), Obj(Obj), Writer(Writer), TypeDB(100) {}
void printFileHeaders() override;
void printSections() override;
@@ -1553,7 +1553,7 @@
TypeBuf.append(Record.begin(), Record.end());
});
- TypeDatabase TypeDB;
+ TypeDatabase TypeDB(CVTypes.records().size());
{
ListScope S(Writer, "MergedTypeStream");
CVTypeDumper CVTD(TypeDB);
@@ -1574,7 +1574,7 @@
{
ListScope S(Writer, "MergedIDStream");
- TypeDatabase IDDB;
+ TypeDatabase IDDB(IDTable.records().size());
CVTypeDumper CVTD(IDDB);
TypeDumpVisitor TDV(TypeDB, &Writer, opts::CodeViewSubsectionBytes);
TDV.setItemDB(IDDB);