Reduce compilation time
-
I have a big project, compilation time six minutes, to reduce the time I am trying to put #include "moc_file.cpp" inside the "file.cpp" (the other things I have already tried), is this a good idea?
-
How would that speed up anything?
the other things I have already tried
What have you tried, specifically?
Some things I know:
- don't do full rebuilds unless you have to - make use of incremental builds
- use forward declarations as much as possible and everywhere (it can speed things up by even 30-40%)
- only include what you use (no
#include <QtGui>
etc.) - use precompiled headers
- use a fast build system (qbs or cmake+ninja, not qmake)
- this is debatable (I don't really recommend it), but you can try lowering the number of build synchronization steps - by reducing number of libraries you compile. Linking libraries cannot be parallelised
- use
ccache
- it can potentially speed things up by even 90+% - if you have more PCs, you can also use
distcc
or some other distributed compilation technology - buy a new PC :D New CPUs have crazy core counts, and when coupled with fast SSD drives compilation times go way down
-
@Massimiliano75
in addition to the excellent points of @sierdzio
A few qt related things,If you use QtCreator, are you sure make is called with the multi core option (thats not the default on Windows)
do you have a sub dir project and you're using the forbidden ordered option?
What compiler are you using? There may be a more optimized one for the OS you're targeting
Where do your files live ? Hopefully not on network path but a local ssd or even ram-drive
Did you make sure to exclude your build folder from your anti virus software ? I have a very invasive Antivirus that I'm forced to use and its taking a whole cpu core to check all files in the build folder while they are being build slower down my build significantly
-
I've already done:
- don't do full rebuilds unless you have to - make use of incremental builds
ok I would like to reduce the time of full compilation because we often change development branches - i use precompiled headers
- i use forward declarations
- i use parallel compilation - j option
- don't do full rebuilds unless you have to - make use of incremental builds
-
@J-Hilk said in Reduce compilation time:
If you use QtCreator, are you sure make is called with the multi core option (thats not the default on Windows)
Yes , i work under linux and i monitor the cpudo you have a sub dir project and you're using the forbidden ordered option?
i have four subdir, but i don't use the forbidden ordered option
What compiler are you using? There may be a more optimized one for the OS you're targeting
linux , gcc x86 64bit
Where do your files live ? Hopefully not on network path but a local ssd or even ram-drive
ssd
Did you make sure to exclude your build folder from your anti virus software ? I have a very invasive Antivirus that I'm forced to use and its taking a whole cpu core to check all files in the build folder while they are being build slower down my build significantly
no antivirusWith #include "moc_file.cpp" inside the "file.cpp" I am reducing the time
-
@Massimiliano75 said in Reduce compilation time:
With #include "moc_file.cpp" inside the "file.cpp" I am reducing the time
Thanks, good to know!
-
@sierdzio said in Reduce compilation time:
With #include "moc_file.cpp" inside the "file.cpp" I am reducing the time
I am intrigued. Does anyone have an explanation for why/how this works? [Discussion forked to https://forum.qt.io/topic/117973/ --JKSH]
Also, how/why did anyone even think of trying it? (The thought has never occurred to me.)
On a separate note:
The single most important tactic I have ever seen for reducing time of an incremental rebuild (not full build) is to clean up the header-to-header include graph. https://xania.org/200712/c-plus-plus-header-dependency-tricks
Even though you mention switching development branches often, if the version control system and the build system are sane you should not have to do a full clean-and-rebuild just to switch branches. (Using git and a qmake build), I switch branches 10+ times per day and only do incremental rebuilds each time.