[cfe-dev] Tips for optimising libclang

Miguel Guedes miguel.a.guedes at gmail.com
Tue Apr 2 10:19:15 PDT 2013


Hello List,


I was hoping someone could give me some tips on how to optimise
creation/reparsing of translation units via libclang as well as code
completion requests.

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 [0] - 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(
		index,
		filename,
		parameters,      [1]
		unsavedFiles, /* to keep it simple, I'm not using 
				  unsaved files at the moment */
		0,
		CXTranslationUnit_PrecompiledPreamble
                  | CXTranslationUnit_CacheCompletionResults);

3) When requesting code completion:

	results = clang_codeCompleteAt(
    		tu,
    		filename,
    		line, col,
    		unsavedFiles,
    		0,
    		CXCodeComplete_IncludeMacros);

Questions:

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
100ms.



[0] http://pastebin.com/aDBGN68R
[1] -I/home/guedesm/prj/omnis/out 
    -I/usr/include/c++/4.7 -I/usr/include/c++/4.7/x86_64-linux-gnu
    -I/usr/include/c++/4.7/backward
    -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include 
    -I/usr/local/include
    -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
    -I/usr/include/x86_64-linux-gnu 
    -I/usr/include


-- 
Miguel




More information about the cfe-dev mailing list