In this article I will tackle libclang’s speed on Windows, in particular Qt Creator’s clang code model.
Qt Creator 3.6.0 fixed the following bug: QTCREATORBUG-15365: Clang Model: code completion speed regression.
The bug report contains information on how to enable Qt Creator’s clang code model statistics. This is done
by setting this environment variable: QT_LOGGING_RULES=qtc.clangbackend.timers=true
.
On Windows Qt Creator will output this information in Windows debugger output. I use DebugView
to view this information.
libclang is used by Qt Creator to provide code completion support. The clang code model is still experimental and not 100% feature equivalent with
the Qt Creator built-in code model.
By using the clang code model it means that Qt Creator uses a real C++ compiler to parse the source code you are editing. It also means
that if you are having a big source file, with lots of includes, it will take some time to do so.
Qt Creator will cache this information in a form of a pch file under %temp%/qtc-clang-[some letters]/preamble-[some numbers].pch
file. The complete
compilation is done only once. The subsequent code completion commands are fast.
I have picked Lyx – The Document Processor as a test project for Qt Creator. Lyx uses Boost and Qt5 and on my Intel(R) Core (TM) i7 CPU
M 620 @ 2.67 GHz Windows 10 powered laptop it takes, for Text3.cpp
, approximately 10 seconds to “compile”.
Even though my laptop has multiple cores, libclang will use only one core to compile Text3.cpp
. What can we do about it? It would be nice if
libclang could use the GPU
Qt Creator 3.6.0 ships with libclang 3.6.2, and for Windows it ships a Visual C++ 2013 32 bit build, unlike Linux where 64 bit is the norm.
I will take clang 3.6.2 and compile it Visual C++ 2013, Visual C++ 2015, Clang 3.7.0 and Mingw-w64 GCC 5.3.0. I have managed to get libclang to
compile Text3.cpp
in approximatively 6 seconds. Which C++ compiler was able to this?