Skip to content

Add support for precompiling server/tango.h (build time reduction)

Michal Liszcz requested to merge github/fork/mliszcz/use-pch into tango-9-lts

server/tango.h includes quite a lot of other headers and is used in most of the files under cppapi and cpp_test_suite directories. Compiling this header again and again in every translation unit consumes more than 50% of build time.

This PR allows to precompile server/tango.h and include precompiled binary instead of plain header.

Below are some numbers from the time command (zsh built-in). Before each make invocation I've deleted the build directory and ran cmake again.

cmake .. -DCMAKE_INSTALL_PREFIX=${PREFIX}/cppTango -DIDL_BASE=${PREFIX}/tangoidl -DOMNI_BASE=${PREFIX}/omniORB -DZMQ_BASE=${PREFIX}/libzmq -DCMAKE_BUILD_TYPE=Debug -DUSE_PCH=ON
make -j 4  787,72s user 85,49s system 367% cpu 3:57,45 total
make -j 4  779,58s user 85,73s system 364% cpu 3:57,53 total
make -j 4  780,02s user 86,20s system 366% cpu 3:56,32 total

cmake .. -DCMAKE_INSTALL_PREFIX=${PREFIX}/cppTango -DIDL_BASE=${PREFIX}/tangoidl -DOMNI_BASE=${PREFIX}/omniORB -DZMQ_BASE=${PREFIX}/libzmq -DCMAKE_BUILD_TYPE=Debug -DUSE_PCH=OFF
make -j 4  1859,02s user 113,27s system 372% cpu 8:49,15 total
make -j 4  1874,94s user 114,89s system 383% cpu 8:38,51 total
make -j 4  1881,58s user 114,88s system 382% cpu 8:42,14 total

Some remarks:

  • tango.h must be precompiled twice (once for libtango and once for tests). This is due to -fPIC/-pie mismatch,
  • due to the above constraint, PCHs are located in build/cppapi and build/cpp_test_suite,
  • PCH must be passed to gcc via -include option
  • absolute path is used with -include to prevent adding new directory via -I(...) - this means that tango.h needs to be copied to the directory containing PCH, as gcc needs to see both,
  • I've conditionally added some defines (VALGRIND _PTHREADS, _REENTRANT) to conf_devtest , compare_test_object, DevTest and FwdTest. They should do no harm and will allow gcc to use PCH for these targets as well (this reduced the build time by 1min).

Merge request reports