Optimize compile time
-
I'm compiling my project just to
Windowsos, i compiling underVisual Studio 2022, i wonder if there's any option or settings, etc
in which could help reduce compiling time?I'm already using pre-compiled header, is it 'ok' to add qt includes like:
#include <QtWidgets/QMainWindow>into the pch? -
I'm compiling my project just to
Windowsos, i compiling underVisual Studio 2022, i wonder if there's any option or settings, etc
in which could help reduce compiling time?I'm already using pre-compiled header, is it 'ok' to add qt includes like:
#include <QtWidgets/QMainWindow>into the pch?i wonder if there's any option or settings, etc in which could help reduce compiling time?
A couple, yes, but first you have to know what the problem actually is. Flipping switches at random won't get you far.
is it 'ok' to add qt includes like: #include <QtWidgets/QMainWindow> into the pch?
In general yes, but keep in mind that this might not get you the effect you're after if you put there too much. Precompiled headers are not magic. Compilation time of the pch itself might increase dramatically and keep in mind that the resulting object file is kinda sticked in front of every other compiled file, so big pch's can increase linking time.
I would start by refactoring includes - make sure you don't put includes in headers unless you absolutely need to. Use forward declarations as much as possible. Analyze your dependencies, especially the transitional ones, so you don't include the same files multiple times. If you use a lot of templates or constexpr see if you can reduce their use or include only where really needed etc.
Since you're using VS2022 there's a nice extension called CompileScore that can help you with pinpointing compilation hotspots and bottlenecks. It lets you dig deep into compilation times to see what actually takes time. It even colors your includes so you can see which of them are the heaviest and need attention.