Maximizing VisualGDB IntelliSense Performance
This tutorial shows how to optimize the performance of VisualGDB’s Clang-based IntelliSense. We will create a basic project using the Boost library using the file layout that causes IntelliSense to be slow. Then we will show how to rearrange the code in the source files and use precompiled headers to dramatically increase IntelliSense performance.
- Start Visual Studio and launch the VisualGDB Linux Project Wizard:
- Pick the name and location for your project:
- Proceed with creating a basic MSBuild-based application. We will use it as the easiest way to install the heavyweight Boost library, however the steps shown in this tutorial will also work for other project types (e.g. CMake or Embedded projects):
- Pick your target and click “Next” to proceed:
- Proceed with the default source uploading settings and click “Finish” to create the project:
- Make sure your target has the boost package installed (on Ubuntu you can install it by running sudo apt install libboost-dev) and try including the <boost/thread.hpp> file after the “using namespace std” line. Then type “boost::” in main() to trigger an IntelliSense popup:The popup will take some time to appear. You can check the exact timing via the View->Clang IntelliSense Status command (search for the “code completion latency” line). This happens because VisualGDB did not manage to cache the boost/thread.hpp file and had to explicitly reparse it before showing the IntelliSense popup.
- VisualGDB provides a special diagnostic view that shows how much it took to parse different parts of the file. Save the file to trigger a reparse, and then click on the timer icon:In this example, it takes over 2 seconds to parse the boost’s thread.hpp file (full parsing is slightly slower than building IntelliSense suggestion lists, as it also looks inside inline function bodies to discover variable references). You can dramatically reduce this time by making sure that boost/thread.hpp ends up inside the main source file’s preamble.
- A preamble in a set of preprocessor directives (e.g. #include or #define) at the top of the file. It also includes the extern “C” statement, but does not include statements like “using namespace“. VisualGDB’s IntelliSense assumes that the preamble in each source file doesn’t change often, and hence can be cached. Because boost/thread.hpp was included after the “using namespace” statement, it was not included in the preamble:
- Move the inclusion point for <boost/thread.hpp> above “using namespace std“. Now it will get cached, dramatically reducing the delay (first IntelliSense popup after changing the preamble will be still slow):
- Code completion in header files works in a similar way. Additionally to the regular directives at the beginning of the header file, the preamble will include any statements (including the using namespace std) inside the main source file, that are before the header’s inclusion point (this works recursively). As soon as these parts are not changed often, IntelliSense will work very fast:
- If you often change the #include<> directives at the top of your source files, you can still improve IntelliSense performance by using precompiled headers. Create a PCH.h file with the following contents:
#pragma once #include <iostream> #include <boost/thread.hpp>
Then specify it in VisualGDB Project Properties -> IntelliSense Settings -> IntelliSense-only precompiled header:
- Now IntelliSense will be fast even if you edit the main source file’s preamble (e.g. reorder the #include<> directives):If you would like to speed up the build as well, consider using precompiled headers for build via the regular VS Project Properties for MSBuild projects.