[Interest] Tricks to improve moc performance?

Adam Light aclight at gmail.com
Mon Dec 23 23:26:29 CET 2019


On Thu, Dec 5, 2019 at 5:09 PM Adam Light <aclight at gmail.com> wrote:

>
> We have almost 600 classes that use Q_OBJECT, so there are a lot of calls
> to moc. We probably don't strictly need the Q_OBJECT macro in some of those
> classes, but I would prefer not to start removing Q_OBJECT unless that's
> the last option.
>
> We also have around 200 paths in our INCLUDEPATH variable. Moving header
> files into fewer directories would allow that to decrease, which should
> improve moc performance.
>
> Does anyone else have any ideas of how we could change our build to
> improve moc performance when Windows decides to be "slow"? Like, for
> example, is there any way to have the moc calls run with only a few moc
> processes running at once but have the rest of the build done with all
> threads running. I'm pretty sure that the OS slowdown has something to do
> with thread contention of some sort.
>
>
 To follow up with my original post, I've made moderate progress by pruning
the number of paths in INCLUDEPATH, removing #include statements from our
header files that aren't actually necessary, and tweaking qmake CONFIG
settings. That has dropped the build time down from close to 5 minutes to
just under 3 minutes.

One idea I had was to combine all files in HEADERS into a single giant .h
file, and then call moc.exe once on that file. The single call to moc.exe
would be executed in a single thread, but it would avoid the need to
rediscover all of the header files from each of the 600 or so moc processes
that would otherwise run.

I was able to get qmake to generate the concatenated .h file for me with
the following commands:
COMBINED_HEADERS = $$shell_path($$absolute_path($${MOC_DIR}/allheaders.h,
$$OUT_PWD))
for (oneHeader, HEADERS): {
    CMD = "type $$shell_quote($$shell_path($$absolute_path($${oneHeader},
$$_PRO_FILE_PWD_))) >>  $${COMBINED_HEADERS}"
    message($${CMD})
    system("$${CMD}")
}

I then manually executed the moc.exe command on the command line, using the
same flags used for all of the other regular moc calls, and it took moc
about 2 seconds, versus over 60 seconds when moc is called separately for
each mocable file. Concatenating all of the header files together did take
some time (maybe 20 seconds), but it's still a huge decrease in build time.

I haven't tried to link in this single moc output file, so there may still
be troubles ahead.

Does anyone know of an existing example of doing the concatenating of
headers properly so that the mega header file is updated when necessary? My
quick and dirty approach given above seems to work so far but I'd be
surprised if it's the best way.

Thanks
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20191223/3c0496c0/attachment.html>


More information about the Interest mailing list