automoc: build mocs_compilation.cpp.o earlier to improve parallelism
While investigating the build time, I found that it would waste some time at the end of the build, compiling moc_compilation.cpp.o
and subsequently linking a single executable. This moc_compilation.cpp.o
object file is presumably built because AUTOMOC
is on, but takes about eight seconds to build.
See this picture for a full build that measures when the compiler starts and ends, the large bar at the bottom is building moc_compilation.cpp.o
, in the top right corner is the final executable (which takes about a second to link with lld). Also visible is that ninja runs out of jobs and wastes some time. The vertical lines mark seconds (this build took 175.4 seconds).
I suppose that if this object is built earlier, then jobs could be better distributed, reducing idle and compile times.
This particular object has the following dependency:
# ninja -t browse ui/qt/CMakeFiles/qtui.dir/qtui_autogen/mocs_compilation.cpp.o
target is built using rule CXX_COMPILER__qtui of
cmake_object_order_depends_target_qtui (order-only)
ui/qt/qtui_autogen/mocs_compilation.cpp
dependent edges build:
run/wireshark
ui/qt/qtui
qtui
is an object library included with the wireshark
executable target. Just running ninja -nvj1 qtui
reveals that the above object is built very late:
[216/223] /usr/bin/clang++ ... -o ui/qt/CMakeFiles/qtui.dir/qtui_autogen/mocs_compilation.cpp.o ...
Just building this single object (ninja -nvj1 ui/qt/CMakeFiles/qtui.dir/qtui_autogen/mocs_compilation.cpp.o
) reveals a few dependencies (19 jobs in total):
- lrelease (for translations)
-
cmake -E cmake_autogen
,cmake -E cmake_autorcc
My question, is there a way to order the autogen target earlier in the dependency list to ensure that its build is started earlier? The goal is to reduce the idle time and therefore reduce the total build time.