Skip to content

Add explicit moc includes to sources for moc-covered headers

Friedrich W. H. Kossebau requested to merge work/kossebau/mocincludes into master
  • speeds up incremental builds as changes to a header will not always need the full mocs_compilation.cpp for all the target's headers rebuild, while having a moc file sourced into a source file only adds minor extra costs, due to small own code and the used headers usually already covered by the source file, being for the same class/struct
  • seems to not slow down clean builds, due to empty mocs_compilation.cpp resulting in those quickly processed, while the minor extra cost of the sourced moc files does not outweigh that in summary. Measured times actually improved by some percent points. (ideally cmake would just skip empty mocs_compilation.cpp & its object file one day)
  • enables compiler to see all methods of a class in same compilation unit to do some sanity checks
  • potentially more inlining in general, due to more in the compilation unit
  • allows to keep using more forward declarations in the header, as with the moc code being sourced into the cpp file there definitions can be ensured and often are already for the needs of the normal class methods

Measurement example:

kdesrc-build --build-only (-j4), always rm -r build/libkdegames, on i5-2520M CPU @ 2.5 GHz & SSD
time average on 5 runs:

  • real (wall clock): 01:02,18 -> 00:58,46 (94 %) with 2 s variation
  • user (sum of threads): 03:06,37 -> 02:48,13 (90 %) with 3 s variation

moc includes generated with script from sdk/kde-dev-scripts!24 (merged) + some fine-tuning with vim-comments or deprecation wrappers.

Checked completeness by this running in the toplevel build dir giving 0:
find . -name mocs_compilation.cpp -exec cat {} \; | grep "#include" | wc -l

Edited by Friedrich W. H. Kossebau

Merge request reports

Loading