Bug 1501903 - Cache the results of inThirdPartyPath. r=andi a=RyanVM
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 25 Oct 2018 21:21:36 +0000
changeset 500883 2058a60f13a7172dec390d9608fe35e2e7761e55
parent 500882 a186639fc5c55c43708a6f897902c714f0dab791
child 500884 38e139673b1933a7b950943ed997eab813924e05
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersandi, RyanVM
bugs1501903
milestone64.0
Bug 1501903 - Cache the results of inThirdPartyPath. r=andi a=RyanVM The function is called a lot for the same paths and is rather costly, so cache the results for each path. Depends on D9758 Differential Revision: https://phabricator.services.mozilla.com/D9759
build/clang-plugin/MozCheckAction.cpp
build/clang-plugin/Utils.h
--- a/build/clang-plugin/MozCheckAction.cpp
+++ b/build/clang-plugin/MozCheckAction.cpp
@@ -18,8 +18,10 @@ public:
   bool ParseArgs(const CompilerInstance &CI,
                  const std::vector<std::string> &Args) override {
     return true;
   }
 };
 
 static FrontendPluginRegistry::Add<MozCheckAction> X("moz-check",
                                                      "check moz action");
+
+DenseMap<unsigned, bool> InThirdPartyPathCache;
--- a/build/clang-plugin/Utils.h
+++ b/build/clang-plugin/Utils.h
@@ -340,19 +340,27 @@ inline bool isPlacementNew(const CXXNewE
     return false;
   const FunctionDecl *Declaration = Expression->getOperatorNew();
   if (Declaration && hasCustomAttribute<moz_heap_allocator>(Declaration)) {
     return false;
   }
   return true;
 }
 
+extern DenseMap<unsigned, bool> InThirdPartyPathCache;
+
 inline bool inThirdPartyPath(SourceLocation Loc, const SourceManager &SM) {
   Loc = SM.getFileLoc(Loc);
 
+  unsigned id = SM.getFileID(Loc).getHashValue();
+  auto pair = InThirdPartyPathCache.find(id);
+  if (pair != InThirdPartyPathCache.end()) {
+    return pair->second;
+  }
+
   SmallString<1024> RawFileName = SM.getFilename(Loc);
   llvm::sys::fs::make_absolute(RawFileName);
   SmallString<1024> FileName;
   llvm::sys::fs::real_path(RawFileName, FileName);
 
   for (uint32_t i = 0; i < MOZ_THIRD_PARTY_PATHS_COUNT; ++i) {
     auto PathB = sys::path::begin(FileName);
     auto PathE = sys::path::end(FileName);
@@ -369,21 +377,23 @@ inline bool inThirdPartyPath(SourceLocat
            ++IPathB, ++IThirdPartyB) {
         if (IPathB->compare_lower(*IThirdPartyB) != 0) {
           break;
         }
       }
 
       // We found a match!
       if (IThirdPartyB == ThirdPartyE) {
+        InThirdPartyPathCache.insert(std::make_pair(id, true));
         return true;
       }
     }
   }
 
+  InThirdPartyPathCache.insert(std::make_pair(id, false));
   return false;
 }
 
 inline bool inThirdPartyPath(const Decl *D, ASTContext *context) {
   D = D->getCanonicalDecl();
   SourceLocation Loc = D->getLocation();
   const SourceManager &SM = context->getSourceManager();