[PATCH] D27840: COFF: Cache the result of library searches.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 15 19:35:15 PST 2016


pcc created this revision.
pcc added a reviewer: ruiu.
pcc added a subscriber: llvm-commits.

File system operations were still dominating the profile on Windows. In this
case we were spending a significant amount of our time repeatedly searching
for libraries as a result of processing linker directives. Address this
by caching whether we have already found a library with a given name. For
chrome_child.dll:

Before: 10.53s
After: 6.88s


https://reviews.llvm.org/D27840

Files:
  lld/COFF/Driver.cpp
  lld/COFF/Driver.h


Index: lld/COFF/Driver.h
===================================================================
--- lld/COFF/Driver.h
+++ lld/COFF/Driver.h
@@ -90,7 +90,7 @@
 
   // Library search path. The first element is always "" (current directory).
   std::vector<StringRef> SearchPaths;
-  std::set<std::string> VisitedFiles;
+  std::set<std::string> VisitedFiles, VisitedLibs;
 
   SymbolBody *addUndefined(StringRef Sym);
   StringRef mangle(StringRef Sym);
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -280,11 +280,12 @@
 Optional<StringRef> LinkerDriver::findLib(StringRef Filename) {
   if (Config->NoDefaultLibAll)
     return None;
+  if (!VisitedLibs.insert(Filename.lower()).second)
+    return None;
   StringRef Path = doFindLib(Filename);
   if (Config->NoDefaultLibs.count(Path))
     return None;
-  bool Seen = !VisitedFiles.insert(Path.lower()).second;
-  if (Seen)
+  if (!VisitedFiles.insert(Path.lower()).second)
     return None;
   return Path;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27840.81709.patch
Type: text/x-patch
Size: 1058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161216/4332933e/attachment.bin>


More information about the llvm-commits mailing list