CLion 2019.2 Help

Performance Tuning Tips

This article gives a summary of helpful techniques that you can use to improve CLion performance on large-scale projects.

Increase memory heap

Enable memory indicator

To check whether performance slowdowns are caused by low heap memory, enable the Show memory indicator option in Settings/Preferences | Appearance & Behavior | Appearance. By default, both JVM and Clangd memory indicators will appear in the bottom right corner:

memory indicators

Adjust -Xmx

To increase memory heap, modify the corresponding JVM option, -Xmx:

  1. Go to Help | Edit Custom VM Options - this action will create a copy of the .vmoptions file in the IDE config directory and open it in the editor.

  2. Set -Xmx to a higher value. For example, -Xmx4096m for 4 GB value instead of the default 2 GB.

  3. Restart CLion.

CLion also warns you if the amount of the free heap memory is less than 5% of the maximum heap size:

low memory warning message

Click Configure to edit -Xmx in the Memory Settings dialog:

change Xmx in Memory Settings

Speed up code analysis

Filter the list of inspections

On-the-fly code analysis is one of the most performance-consuming processes in CLion. To lighten it up, shorten the list of inspections in Settings / Preferences | Editor | Inspections (see other ways of disabling and suppressing inspections).

In particular, consider disabling the Data Flow Analysis group and the General | Simplifiable statement inspection:

disable performance-consuming inspections

You will always be able to run inspections on demand using the Code | Inspect Code command and explore the results in a separate tool window without affecting the editor. Also, you can postpone code analysis (and on-the-fly refactoring) until commit by setting up the Before Commit options.

Tune analysis for a file

To change the level of code analysis for the currently opened file, click the Hector icon the Hector icon on the Status bar or run Code | Configure Current File Analysis Ctrl+Shift+Alt+H:

Hector the Inspector popup

Move the slider to one of the available positions:

  • None to turn off the highlighting completely;

  • Syntax to show syntax problems only;

  • Inspections (default) to show syntax problems and inspection issues.

Toggle Power Save mode

As an alternative to configuring individual checks or files one by one, try Power Save Mode. It disables all inspections and other highly-consuming background tasks for the entire IDE.

To enable Power Save Mode, set the corresponding checkbox in the Hector popup (see the screenshot above), or call File | Power Save Mode.

Check the Clangd-based engine

CLion incorporates a complementary Clangd-based language engine which is enabled by default. Currently, it works for error/warning annotation, certain navigation tasks, code formatting via ClangFormat, and code highlighting with quick-fixes.

In most cases, Clangd-based engine works faster than the built-in one (and sometimes provides more accurate results). However, it is not used for all operations. For example, Clangd provides the location for a quick-fix, while the fix itself is performed by the CLion’s own engine. Or, Find Usages employs Clangd to search through the files currently opened in the editor and the CLion’s own engine for all other usages.

We recommend you take Clangd engine specifics into account when investigating performance issues. Use Settings / Preferences | Languages & Frameworks | C/C++ | Clangd to experiment with the engine settings and see if they affect the performance on certain tasks.

Speed up indexing

Exclude directories and file types

By default, CLion indexes all the directories listed in CMakeLists.txt (sources and include_directories paths) for the purpose of correct resolve. Meanwhile, your project may contain folders with binaries, logs, or build artifacts, which do not affect CLion’s code insight. Also, some folders’ indexing can be too expensive due to their size or location. So it is reasonable to exclude such folders manually: right-click the directory in the project tree and choose Mark Directory as.. | Excluded.

mark directory as excluded

Since the symbols from the excluded files remain uncompleted for CLion, the following features are not available for such files: code completion and auto-import (except for the case when the excluded directory is marked with include_directories in CMakeLists.txt), code generation, Find in Path (except for the scope of the currently opened files), navigation, and refactorings.

Another way to eliminate files like logs or generated data from indexing is to exclude them by file type in Settings / Preferences | Editor | File Types:

ignored files types

Work with smaller CMake sub-projects

The scope of files being parsed is determined by the loaded CMake script. So if your project is split into several subdirectories with self-contained CMakeLists.txt in each of them, you can load smaller sub-projects separately (for this, run Load CMake project on sub-CMakeLists.txt):

load CMake sub-projects

Another alternative for the case when you need to explore only a part of a big project is to create a compilation database, reduce it to the part of interest, and then open as a project in CLion.

Eliminate heavy parsing with the _CLION_IDE__ macro

IDE freezes may happen during the parsing of intricate preprocessor macros. To eliminate such problematic definitions from your code, replace them with some dummy ones using the __CLION_IDE__ macro:

CLion IDE macro

This macro affects parsing only, and it is undefined when you build or run your code.

Report performance problems

If you experience an IDE freeze or high CPU/memory usage, and the tips listed above do not help, please provide us with the IDE logs, thread dumps, and snapshots. See this instruction for details on how to retrieve and send them.

Last modified: 22 August 2019