Speed up debug version of LibTooling AST parsing

We are using Clang LibTooling for source-to-source conversion. Size of converted headers is around 10MB.

Release version of our conversion utility works fine, but debug version is spending 20 seconds in clang::ParseAST.

Is there any chance how to speed up parsing, for example using precompiled headers (or storing parsed AST)?

Could you please point me in the right direction?

Best regards
Jan Rysavy

Unless you need the actual Debug build for anything, maybe try sticking to assertions and a release build? (-DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release) Release build is fast, small, and with enough assertions (and maybe putting “llvm/Support/Debug.h” into the file and calling the frontend with -debug?) you could get most of the stuff you need for debugging.

Jan Ryšavý via cfe-dev <cfe-dev@lists.llvm.org> ezt írta (időpont: 2020. febr. 17., H, 10:19):

Thank you for this idea. Trouble with LibTooling in Release build is we must use Release build also for our utility (Windows executable), otherwise we are receiving following RTL conflicts:

1>clangAST.lib(DeclarationName.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in CmdLineUtils.obj
1>clangAST.lib(ASTTypeTraits.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in CmdLineUtils.obj
etc.

Of course we can turn off optimizations and debug in Release build...

Best regards
Jan Rysavy

You can normally add -include-pch file.pch to the args passed to the tooling
call, we do it in LibreOffice
(https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/sharedvisitor/analyzer.cxx?id=9ab2703d5c212746c961dcb238a4c3025d3a2587#n274).

Thank you for this idea. Trouble with LibTooling in Release build is we must use Release build also for our utility (Windows executable), otherwise we are receiving following RTL conflicts:

Why would you not want to build your utility in Release mode in any case where performance/runtime speed of the program matters to you? Perhaps some more context would be helpful to understand the tradeoffs you’re trying to make.

Thank you, -include-pch file.pch is exactly what I was looking for!

The debug version now takes 10 seconds instead of 20.

Best regards
Jan Rysavy