Author: Jaroslav Sevcik
Date: 2020-01-22T15:20:06+01:00
New Revision: 4481eefbe8425c63289186dd13319aaa7043e67f

URL: 
https://github.com/llvm/llvm-project/commit/4481eefbe8425c63289186dd13319aaa7043e67f
DIFF: 
https://github.com/llvm/llvm-project/commit/4481eefbe8425c63289186dd13319aaa7043e67f.diff

LOG: [ASTImporter] Properly delete decls from SavedImportPaths

Summary:
We see a significant regression (~40% slower on large codebases) in expression 
evaluation after https://reviews.llvm.org/rL364771. A sampling profile shows 
the extra time is spent in SavedImportPathsTy::operator[] when called from 
ASTImporter::Import. I believe this is because ASTImporter::Import adds an 
element to the SavedImportPaths map for each decl unconditionally (see 
https://github.com/llvm/llvm-project/blob/7b81c3f8793d30a4285095a9b67dcfca2117916c/clang/lib/AST/ASTImporter.cpp#L8256).

To fix this, we call SavedImportPathsTy::erase on the declaration rather than 
clearing its value vector. That way we do not accidentally introduce new empty 
elements.  (With this patch the performance is restored, and we do not see 
SavedImportPathsTy::operator[] in the profile anymore.)

Reviewers: martong, teemperor, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, cfe-commits

Tags: #clang

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

Added: 
    

Modified: 
    clang/lib/AST/ASTImporter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1f2ce30398c9..9dd20e2d5921 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8253,7 +8253,7 @@ Expected<Decl *> ASTImporter::Import(Decl *FromD) {
           // FIXME Should we remove these Decls from the LookupTable,
           // and from ImportedFromDecls?
       }
-    SavedImportPaths[FromD].clear();
+    SavedImportPaths.erase(FromD);
 
     // Do not return ToDOrErr, error was taken out of it.
     return make_error<ImportError>(ErrOut);
@@ -8286,7 +8286,7 @@ Expected<Decl *> ASTImporter::Import(Decl *FromD) {
   Imported(FromD, ToD);
 
   updateFlags(FromD, ToD);
-  SavedImportPaths[FromD].clear();
+  SavedImportPaths.erase(FromD);
   return ToDOrErr;
 }
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to