{"id":6068,"date":"2020-05-13T16:19:26","date_gmt":"2020-05-13T23:19:26","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=6068"},"modified":"2020-05-13T16:19:26","modified_gmt":"2020-05-13T23:19:26","slug":"maximizing-visualgdb-intellisense-performance","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/intellisense\/performance\/","title":{"rendered":"Maximizing VisualGDB IntelliSense Performance"},"content":{"rendered":"<p>This tutorial shows how to optimize the performance of VisualGDB&#8217;s Clang-based IntelliSense. We will create a basic project using the <a href=\"https:\/\/www.boost.org\/\">Boost<\/a> 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.<\/p>\n<ol>\n<li>Start Visual Studio and launch the VisualGDB Linux Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-newprj-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6069\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-newprj-2.png\" alt=\"\" width=\"966\" height=\"624\" \/><\/a><\/li>\n<li>Pick the name and location for your project: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-demo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6070\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-demo.png\" alt=\"\" width=\"966\" height=\"624\" \/><\/a><\/li>\n<li>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): <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-msb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6071\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-msb.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Pick your target and click &#8220;Next&#8221; to proceed:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/04-target-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6072\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/04-target-1.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Proceed with the default source uploading settings and click &#8220;Finish&#8221; to create the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/05-upload.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6073\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/05-upload.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Make sure your target has the boost package installed (on Ubuntu you can install it by running <strong>sudo apt install libboost-dev<\/strong>) and try including the <strong>&lt;boost\/thread.hpp&gt;<\/strong> file <strong>after<\/strong> the &#8220;<strong>using namespace std<\/strong>&#8221; line. Then type &#8220;boost::&#8221; in <strong>main()<\/strong> to trigger an IntelliSense popup:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/latency.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6079\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/latency.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a>The popup will take some time to appear. You can check the exact timing via the <strong>View-&gt;Clang IntelliSense Status<\/strong> command (search for the &#8220;code completion latency&#8221; line). This happens because VisualGDB did not manage to cache the <strong>boost\/thread.hpp<\/strong> file and had to explicitly reparse it before showing the IntelliSense popup.<\/li>\n<li>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:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/timing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6080\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/timing.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a>In this example, it takes over 2 seconds to parse the boost&#8217;s <strong>thread.hpp<\/strong> 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 <strong>boost\/thread.hpp<\/strong> ends up inside the main source file&#8217;s <strong>preamble<\/strong>.<\/li>\n<li>A preamble in a set of preprocessor directives (e.g. <strong>#include<\/strong> or <strong>#define<\/strong>) at the top of the file. It also includes the <strong>extern &#8220;C&#8221;<\/strong> statement, but does not include statements like &#8220;<strong>using namespace<\/strong>&#8220;. VisualGDB&#8217;s IntelliSense assumes that the preamble in each source file doesn&#8217;t change often, and hence can be cached. Because <strong>boost\/thread.hpp<\/strong> was included after the &#8220;<strong>using namespace<\/strong>&#8221; statement, it was not included in the preamble:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/06-latency.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6074\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/06-latency.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Move the inclusion point for<strong> &lt;boost\/thread.hpp&gt;<\/strong> above &#8220;<strong>using namespace std<\/strong>&#8220;. Now it will get cached, dramatically reducing the delay (first IntelliSense popup after changing the preamble will be still slow):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08-faster.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6075\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08-faster.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>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 <strong>using namespace std<\/strong>) inside the main source file, that are before the header&#8217;s inclusion point (this works recursively). As soon as these parts are not changed often, IntelliSense will work very fast:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/09-header.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6076\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/09-header.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>If you often change the <strong>#include&lt;&gt;<\/strong> directives at the top of your source files, you can still improve IntelliSense performance by using precompiled headers. Create a\u00a0 PCH.h file with the following contents:\n<pre class=\"\">#pragma once\r\n\r\n#include &lt;iostream&gt;\r\n#include &lt;boost\/thread.hpp&gt;<\/pre>\n<p>Then specify it in VisualGDB Project Properties -&gt; IntelliSense Settings -&gt; IntelliSense-only precompiled header:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/10-pch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6077\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/10-pch.png\" alt=\"\" width=\"864\" height=\"581\" \/><\/a><\/li>\n<li>Now IntelliSense will be fast even if you edit the main source file&#8217;s preamble (e.g. reorder the <strong>#include&lt;&gt;<\/strong> directives):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/fast.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6081\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/fast.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a>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.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to optimize the performance of VisualGDB&#8217;s Clang-based IntelliSense. We will create a basic project using the<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[134],"tags":[52,206],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6068"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=6068"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6068\/revisions"}],"predecessor-version":[{"id":6082,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6068\/revisions\/6082"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=6068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=6068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=6068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}