COFF: Cache the result of library searches.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 16 Dec 2016 03:45:59 +0000 (03:45 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 16 Dec 2016 03:45:59 +0000 (03:45 +0000)
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

Differential Revision: https://reviews.llvm.org/D27840

llvm-svn: 289915

lld/COFF/Driver.cpp
lld/COFF/Driver.h

index 64cc583..e2b5e49 100644 (file)
@@ -280,11 +280,12 @@ StringRef LinkerDriver::doFindLib(StringRef Filename) {
 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;
 }
index fb1f9a8..e811464 100644 (file)
@@ -91,6 +91,7 @@ private:
   // Library search path. The first element is always "" (current directory).
   std::vector<StringRef> SearchPaths;
   std::set<std::string> VisitedFiles;
+  std::set<std::string> VisitedLibs;
 
   SymbolBody *addUndefined(StringRef Sym);
   StringRef mangle(StringRef Sym);