[PATCH] D121006: Speedup dsymutil when working with big project.

C-凡 via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 5 05:07:01 PST 2022


C-_-fan updated this revision to Diff 413209.
C-_-fan added a comment.

I am abandoned the change about `rfind`, and replaced`std::unordered_map<uint64_t, std::vector<StringRef>>` with ` SmallDenseMap<uint64_t, SmallVector<StringRef>>;

In my test, now it take more time because `rfind` performance rollback; but `SmallDenseMap` and `SmallVector` is fast than  `unordered_map` and `vector`.

I will try `-fvisibility=hidden` next week.

Please reivew it agagin. If can not merge still, how can I close this revision? Or this will close auto after timeout?

Thanks again.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121006/new/

https://reviews.llvm.org/D121006

Files:
  llvm/tools/dsymutil/MachODebugMapParser.cpp


Index: llvm/tools/dsymutil/MachODebugMapParser.cpp
===================================================================
--- llvm/tools/dsymutil/MachODebugMapParser.cpp
+++ llvm/tools/dsymutil/MachODebugMapParser.cpp
@@ -9,6 +9,7 @@
 #include "BinaryHolder.h"
 #include "DebugMap.h"
 #include "MachOUtils.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Path.h"
@@ -51,6 +52,11 @@
   BinaryHolder BinHolder;
   /// Map of the binary symbol addresses.
   StringMap<uint64_t> MainBinarySymbolAddresses;
+
+  /// Binary symbol addresses to names map, to speedup
+  /// `getMainBinarySymbolNames`;
+  SmallDenseMap<uint64_t, SmallVector<StringRef>> MainBinaryAddresses2NamesMap;
+
   StringRef MainBinaryStrings;
   /// The constructed DebugMap.
   std::unique_ptr<DebugMap> Result;
@@ -74,7 +80,7 @@
                             sys::TimePoint<std::chrono::seconds> Timestamp);
   void resetParserState();
   uint64_t getMainBinarySymbolAddress(StringRef Name);
-  std::vector<StringRef> getMainBinarySymbolNames(uint64_t Value);
+  SmallVector<StringRef> getMainBinarySymbolNames(uint64_t Value);
   void loadMainBinarySymbols(const MachOObjectFile &MainBinary);
   void loadCurrentObjectFileSymbols(const object::MachOObjectFile &Obj);
   void handleStabSymbolTableEntry(uint32_t StringIndex, uint8_t Type,
@@ -531,13 +537,18 @@
 }
 
 /// Get all symbol names in the main binary for the given value.
-std::vector<StringRef>
+SmallVector<StringRef>
 MachODebugMapParser::getMainBinarySymbolNames(uint64_t Value) {
-  std::vector<StringRef> Names;
-  for (const auto &Entry : MainBinarySymbolAddresses) {
-    if (Entry.second == Value)
-      Names.push_back(Entry.first());
+
+  auto result = MainBinaryAddresses2NamesMap.find(Value);
+  if (result != MainBinaryAddresses2NamesMap.end()) {
+    return result->second;
   }
+
+  /// used by `loadMainBinarySymbols`
+  SmallVector<StringRef> Names;
+  MainBinaryAddresses2NamesMap[Value] = Names;
+
   return Names;
 }
 
@@ -547,6 +558,8 @@
     const MachOObjectFile &MainBinary) {
   section_iterator Section = MainBinary.section_end();
   MainBinarySymbolAddresses.clear();
+  MainBinaryAddresses2NamesMap.clear();
+
   for (const auto &Sym : MainBinary.symbols()) {
     Expected<SymbolRef::Type> TypeOrErr = Sym.getType();
     if (!TypeOrErr) {
@@ -588,10 +601,14 @@
     if (Name.size() == 0 || Name[0] == '\0')
       continue;
     // Override only if the new key is global.
-    if (Extern)
+    if (Extern) {
       MainBinarySymbolAddresses[Name] = Addr;
-    else
-      MainBinarySymbolAddresses.try_emplace(Name, Addr);
+      getMainBinarySymbolNames(Addr).push_back(Name);
+    } else {
+      if (MainBinarySymbolAddresses.try_emplace(Name, Addr).second) {
+        getMainBinarySymbolNames(Addr).push_back(Name);
+      }
+    }
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121006.413209.patch
Type: text/x-patch
Size: 2877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220305/0cec4c3f/attachment.bin>


More information about the llvm-commits mailing list