This is an archive of the discontinued LLVM Phabricator instance.

Speed up compilation of ASTImporter
ClosedPublic

Authored by rnk on Jan 29 2020, 2:42 PM.

Details

Summary

Avoid recursively instantiating importSeq. Use initializer list
expansion to stamp out a single instantiation of std::tuple of the
deduced sequence of types, and thread the error around that tuple type.
Avoids needlessly instantiating std::tuple N-1 times.

new time to compile: 0m25.985s
old time to compile: 0m35.563s

new obj size: 10,000kb
old obj size: 12,332kb

I found the slow TU by looking at ClangBuildAnalyzer results, and looked
at -ftime-trace for the file in chrome://tracing to find this.

Tested with: clang-cl, MSVC, and GCC.

Diff Detail

Event Timeline

rnk created this revision.Jan 29 2020, 2:42 PM
Herald added a reviewer: shafik. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
rnk updated this revision to Diff 241297.Jan 29 2020, 2:43 PM
  • remove unintended hack to test MSVC

Unit tests: pass. 62309 tests passed, 0 failed and 838 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

rnk added a comment.Jan 29 2020, 2:57 PM

The Expected<std::tuple<Ts...>> and std::tie<Ts...> instantiations are still expensive, and they seem avoidable. We could use this code pattern instead:

ExpectedType
ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
  QualType ToElementType = T->getElementType();
  Expr *ToSizeExpr = T->getSizeExpr();
  SourceRange ToBracketsRange = T->getBracketsRange();
  if (Error E = importSeq(ToElementType, ToSizeExpr, ToBracketsRange))
    return E;

  return Importer.getToContext().getVariableArrayType(
      ToElementType, ToSizeExpr, T->getSizeModifier(),
      T->getIndexTypeCVRQualifiers(), ToBracketsRange);
}

Compare to the current pattern:
https://github.com/llvm/llvm-project/blob/master/clang/lib/AST/ASTImporter.cpp#L1176

importSeq would take its parameters by reference. One by one, it would replace them in place, or report an error.

Unit tests: fail. 62308 tests passed, 1 failed and 838 were skipped.

failed: libc++.std/thread/futures/futures_async/async.pass.cpp

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

martong accepted this revision.Jan 30 2020, 4:19 AM

Thanks for the patch! Looks good to me!

clang/lib/AST/ASTImporter.cpp
192

Thanks for thinking about it. This way we can keep the original behavior i.e. the import is stopped on the first error.

This revision is now accepted and ready to land.Jan 30 2020, 4:19 AM
This revision was automatically updated to reflect the committed changes.