[ASTImporter] Properly delete decls from SavedImportPaths
authorJaroslav Sevcik <jarin@google.com>
Wed, 22 Jan 2020 14:19:44 +0000 (15:19 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Wed, 22 Jan 2020 14:20:06 +0000 (15:20 +0100)
commit4481eefbe8425c63289186dd13319aaa7043e67f
treeacdfe3c2b71e49054d3606b2407404a03c2c5059
parente3b15ed376f3753d2a4e16281f8230e4ffed41ba
[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
clang/lib/AST/ASTImporter.cpp