M. Lee
M. Lee

Reputation: 127

Visual Studio Code C++ Intellisense Performance Problems

I have a bigger C++ Project. I use the Micrsoft C++ Extension with the default settings. Intellisense takes sometimes over 1 minute to catch up with suggestions. In order to solve the problem, I went through the settings. I've seen it is possible to set the Intellisense engine to "Tag Parser", it solves all the performance problems as expected, but unfortunately, it deactivates Error Squiggles. Is it possible to combine Tag Parser Intellisense with the default error checking, if the error checking takes a minute it wouldnt be a such a problem? Or do you have other ideas to solve the performance problem?

Upvotes: 3

Views: 14826

Answers (1)

boocs
boocs

Reputation: 599

Depends on what compiler your running. I'm using Visual Studio Build Tools. For my UE4 project, source file Intellisense is pretty snappy but header files are really slow. Sadly I believe headers will always be slow on large project's using the default Intellisense. This is because VSCode recalculates Intellisense with every line of a header file you write.

Off topic info: This is also why you should disable Auto PCH with “C_Cpp.intelliSenseCacheSize” set to 0. Let's say you have a class with a large AutoPCH cache file of 1 Gigabyte (not uncommon with Unreal Engine). VSCode is now deleting and writing this cache with every line you type in a header file. This won't help with Intellisense speed unfortunately.

Back to topic:

Make sure to custom tailor your "C_Cpp.default.includePath" and only include the paths you need. This is used for Default Intellisense but will also be used for Tag Parser if you don't specify any Tag Parser path with "C_Cpp.default.browse.path". Also note that any path in "C_Cpp.default.includePath" is NOT recursively searched for subfolders. You can override this behavior by adding /** to the end of the path. But use it wisely.

For a large project, a better way than using the includePath settings is to use compile commands (compilation database). "C_Cpp.default.compileCommands" lets you use a json file to custom tailor every include path for every header and source file you have. So now default Intellisense is only using the include files it needs for a particular file. You'll have to research on how to create a compile commands json file. There are tools that can auto create this. Unreal Engine actually moved to compile commands for 4.26 but there were no speedups because they still include everything for every file. I believe they have to do it this way based on how UE4 header includes are setup but I'd have to research.

Another way is to limit the #includes in header files and use forward declarations. Put your #includes in source files. This is probably one of the main reasons Unreal Engine header Intellisense is so slow. When creating a class it auto includes header files in the classes header file. Those included headers also include other headers and so on. So when VSCode recalculates header file Intellisense it's very slow. Source files don't seem to care though.

More info:

I forgot to mention about Tag Parser Intellisense. Tag parser info relies on "C_Cpp.default.browse.path" for include files. If you don't specify anything in "C_Cpp.default.browse.path" then:

  • Anything in "C_Cpp.default.includePath" will be use for tag parser Intellisense.
  • Your project's path will automatically be added (see Note below on why this might be bad)

Note: Any path used for the browse path that doesn't have /* at the end will be searched recursively for any subfolders that also have header files to cache.

Note: For multifolder projects, all folder project directories(recursive) will also be added to the tag parser includes for one big Tag Parser cache file.

The Tag Parser is still used when using Default Intellisense. It's used for switching between header and source (Alt+O) and for finding symbols. So you should still tweak the Tag Parser paths to your liking.

For large projects the Tag Parser can take 20+ minutes to finish creating it's cache file when you first open the project. You wont get Tag Parser Intellisense until it's finished. For Unreal Engine 4.26 this file is around 1.5 Gigabytes. Good thing though is that is doesn't get deleted and recreated like the Default Intellisense cache files.

You may need to tweak your "C_Cpp.default.browse.path" instead of not specifying one and and letting VSCode do what it wants.

I will say for source files you will miss having Default (Context Aware) Intellisense. But you can try Tag Parser Intellisense if you can get it to work.

Note: You can see when Intellisense is working. Default Intellisense is a fire symbol and Tag Parser Intellisense is a cylinder found on the bottom bar.

Upvotes: 5

Related Questions