I am new to precompiled headers, and am just wondering what to include. Our project has about 200 source files.
So, do I literally include every third party library?
If I use a map in three source files, do I add it? What if I use it one, do I add it? Do I need to remove the old direct include or are the ifdef and pragma once directives still working?
Are there any third party libraries you wouldn't add?
Doesn't the precompiled header then get massive?
As in, isn't there an overhead of having all these headers included everywhere all of a sudden, even in precompiled form?
EDIT:
I found some information on clang:
A precompiled header implementation improves performance when:
- Loading the PCH file is significantly faster than re-parsing the bundle of headers stored within the PCH file. Thus, a precompiled header design attempts to minimize the cost of reading the PCH file. Ideally, this cost should not vary with the size of the precompiled header file.
- The cost of generating the PCH file initially is not so large that it counters the per-source-file performance improvement due to eliminating the need to parse the bundled headers in the first place. This is particularly important on multi-core systems, because PCH file generation serializes the build when all compilations require the PCH file to be up-to-date.
Clang's precompiled headers are designed with a compact on-disk representation, which minimizes both PCH creation time and the time required to initially load the PCH file. The PCH file itself contains a serialized representation of Clang's abstract syntax trees and supporting data structures, stored using the same compressed bitstream as LLVM's bitcode file format.
Clang's precompiled headers are loaded "lazily" from disk. When a PCH file is initially loaded, Clang reads only a small amount of data from the PCH file to establish where certain important data structures are stored. The amount of data read in this initial load is independent of the size of the PCH file, such that a larger PCH file does not lead to longer PCH load times. The actual header data in the PCH file--macros, functions, variables, types, etc.--is loaded only when it is referenced from the user's code, at which point only that entity (and those entities it depends on) are deserialized from the PCH file. With this approach, the cost of using a precompiled header for a translation unit is proportional to the amount of code actually used from the header, rather than being proportional to the size of the header itself.
To me this seems to indicate that at least clang:
- has taken care to make load times of precompiled headers independent of size.
- Use times of precompiled headers are independent of precompiled header size, and are proportional to amount of used information
- Contrary to answers given so far, this seems to indicate that even when included an external file (say
<map>
) just once, it is worthwhile including it in the precompiled headers (will still speed up re-compilation of that sourcefile)
There must be some sort of map to map out all the info. This map might get larger, but maybe that isn't so important? Not sure whether I got this right though, or whether it applies to all compilers...