[Interest] Tricks to improve moc performance?

Uwe Rathmann Uwe.Rathmann at tigertal.de
Fri Dec 6 09:42:22 CET 2019


On 12/6/19 2:09 AM, Adam Light wrote:

> Does anyone else have any ideas of how we could change our build to 
> improve moc performance when Windows decides to be "slow"?

Something you can try is to include the moc file at the end of your cpp
file. This can be done like this:

#include "moc_XYZ.cpp"

This type of construction is at least supported by qmake.

This does not reduce the number of moc runs, but it reduces the number
of compiler runs. As a rule of thumb for not too large classes I would
expect, that ~50% of the compile time is spent inside the Qt headers and
by including the moc file the overall compile time goes down by 33% as
the headers need to be processed only once.

A side note: the code of Qwt project runs with all Qt versions >= 4.4
and therefore allows to compare the impact of the Qt headers on the
compile time. It is some time ago, when I did this, but the differences
were significant. IIRC there was a major slowdown around ~4.7 that gets
worse during the Qt5 cycle.

HTH,
Uwe



More information about the Interest mailing list