pre-compiled headers compared to same headers built to .so file objects building time and exectuion time speed

60 Views Asked by At

what is faster? pre-compiled headers or same headers built to objects?

Question: Do I still need precompiled headers If I move to model above? Anything else you'd advise to speed up time to update?

I used pre-compiled headers and it seem to slightly speed up compilation.

In my case some part moved out from main app to decrease time to update project (compilation, building, execution. time)

I considering to build all neat, fully debugged functions to .so object files and link it accordingly to dependent apps

2

There are 2 best solutions below

2
Petr Skocik On

Precompiled headers only cache header parsing. The parsed header still needs to be integrated into the rest of the C/C++ file and the result still needs to be optimized.

SO files are the UNIX flavor of dynamic libraries. Both static and dynamic libraries contained fully compiled and optimized functions that only need to be linked.

Linking finished external nontrivial functions will always be faster than expanding inline functions from (compiled or plaintext) header files.

Moving the contents of a header file to an object file/library doesn't really make sense, though. A normally used header file should only contain macros, type/type-alias definitions, inline functions, and, in C++, template definitions. None of that those generate linkable objects (external symbol definitions). Compiling a normal header file into an object file should always yield an empty object file.

Moving inlinable code from header files to C/C++ files (or at least isolating rarely used inline code away from a frequently included header files) while making it noninlinable is always a good idea as far as build times are concerned, but changing a function from inlinable to noninlinable can have noticeable runtime performance consequences where inlining is truly warranted (rare; usually very small functions only), so it shouldn't be done mindlessly.

0
MSalters On

You're missing C++ modules (introduced with C++20)

C++ headers do not build to objects, so there is no comparison here which you can make.