It’s true that nested containers don’t usually perform well, but in this case the outer vector *never* resizes.  So it seems like it should be ok?<br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 19, 2018 at 4:08 PM Reid Kleckner via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">rnk added inline comments.<br>
<br>
<br>
================<br>
Comment at: llvm/include/llvm/DebugInfo/PDB/Native/TpiHashing.h:60<br>
+    codeview::UnionRecord Union;<br>
+  };<br>
+<br>
----------------<br>
You will probably have to name the union field for this to build with all supported compilers.<br>
<br>
<br>
================<br>
Comment at: llvm/include/llvm/DebugInfo/PDB/Native/TpiStream.h:87<br>
<br>
+  std::vector<std::vector<codeview::TypeIndex>> HashMap;<br>
+<br>
----------------<br>
Nested C++ containers don't usually perform the best. Here come some obnoxious data structure micro-optimization suggestions down below!<br>
<br>
<br>
<br>
================<br>
Comment at: llvm/lib/DebugInfo/PDB/Native/TpiStream.cpp:146<br>
<br>
+void TpiStream::buildHashMap() {<br>
+  if (!HashMap.empty())<br>
----------------<br>
How about this:<br>
1. Allocate an array of TypeIndex of size `TypeIndexEnd - TypeIndexBegin`, i.e. an array of all the type indices in the hash table.<br>
2. Make HashMap a `std::vector<std::pair<unsigned, unsigned>>`, where these are begin/end indices of ranges into the previous array. We can write a helper that takes a hash value and returns an `ArrayRef<TypeIndex>` using these two arrays.<br>
3. Build a temporary array of pairs of HashValue+TypeIndex, and sort it by hash value.<br>
4. Iterate over the sorted array of hash values and type indices. Push each type index onto the array. When the hash value changes, store a pair of begin/end indices for the type indices that share this hash code into the HashMap.<br>
<br>
<br>
================<br>
Comment at: llvm/lib/DebugInfo/PDB/Native/TpiStream.cpp:157<br>
+  while (TIB < TIE) {<br>
+    uint32_t HV = HashValues[TIB.toArrayIndex()];<br>
+    HashMap[HV].push_back(TIB++);<br>
----------------<br>
If `HV >= Header->NumHashBuckets`, I would report an error or just drop the type. We could hash the type ourselves as a recovery, but it's a corrupt input file, anything but UB or crashing works.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D52283" rel="noreferrer" target="_blank">https://reviews.llvm.org/D52283</a><br>
<br>
<br>
<br>
</blockquote></div>