[cfe-dev] Tips for optimising libclang
miguel.a.guedes at gmail.com
Tue Apr 2 10:19:15 PDT 2013
I was hoping someone could give me some tips on how to optimise
creation/reparsing of translation units via libclang as well as code
At the moment I'm getting over 1500 ms on average each time a TU is
created for a control source file I use and only marginally less when
it's reparsed. Code completion takes on average about 1000 ms (never
less). This on an i7 with 12GB of memory; system is amd64 Linux 3.5.0-27
and clang version 3.3 (trunk 170425).
The project's PCH includes can be viewed on pastebin  - STL and Boost
are among the includes.
Here's how I'm handling a source file with libclang:
1) Create index if it hasn't been created yet:
index = clang_createIndex(0, 0);
2) Create TU:
tu = clang_parseTranslationUnit(
unsavedFiles, /* to keep it simple, I'm not using
unsaved files at the moment */
3) When requesting code completion:
results = clang_codeCompleteAt(
1) I haven't noticed any improvement in performance when adding more
source files (creating more TUs) that belong to the same project as the
control source file I mentioned above. Shouldn't it be the case that
libclang should reuse the outputs generated when parsing include files
shared by more than one source file?
1.1) If not, can it be done manually?
2) How can performance be improved? Before starting this project I was
hoping for (re-)parsing and code completion times not greater than
More information about the cfe-dev