You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-fpch-codegen and -fpch-debuginfo generate shared code and/or debuginfo for contents of a precompiled header in a separate object file. This object file needs to be linked in, but its contents do not need to be generated for other objects using the precompiled header. This should usually save compile time. If not using clang-cl, the separate object file needs to be created explicitly from the precompiled header. Example of use:
Using -fpch-instantiate-templates when generating the precompiled header usually increases the amount of code/debuginfo that can be shared.
In some cases, especially when building with optimizations enabled, using -fpch-codegen may generate so much code in the shared object that compiling it may be a net loss in build time.
Since headers may bring in private symbols of other libraries, it may be sometimes necessary to discard unused symbols (such as by adding -Wl,–gc-sections on ELF platforms to the linking command, and possibly adding -fdata-sections -ffunction-sections to the command generating the shared object).
In short, -fpch-codegen and -fpch-debuginfo can potentially improve compile times when using precompiled headers, but it requires build system support. The precompiled header (as in the .gch) has to be compiled into an object file that should be linked against. My understanding is that this allows deduplicating some code generation. The actual gain probably would vary a lot between applications and their use of precompiled headers.
It appears that LibreOffice has implemented support for this in their build system, and this blog post claims compile times can be improved by 60% by using these (+-fpch-instantiate-templates, which does not require build system support) compared to just using a precompiled header.
There doesn't seem to be any general purpose build system that has implemented this yet, unfortunately.
This discussion was converted from issue #534 on October 17, 2021 03:21.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
From https://releases.llvm.org/11.0.0/tools/clang/docs/ReleaseNotes.html#new-compiler-flags:
In short,
-fpch-codegen
and-fpch-debuginfo
can potentially improve compile times when using precompiled headers, but it requires build system support. The precompiled header (as in the.gch
) has to be compiled into an object file that should be linked against. My understanding is that this allows deduplicating some code generation. The actual gain probably would vary a lot between applications and their use of precompiled headers.It appears that LibreOffice has implemented support for this in their build system, and this blog post claims compile times can be improved by 60% by using these (+
-fpch-instantiate-templates
, which does not require build system support) compared to just using a precompiled header.There doesn't seem to be any general purpose build system that has implemented this yet, unfortunately.
CMake issue with some discussion on the topic: https://gitlab.kitware.com/cmake/cmake/-/issues/21133
Beta Was this translation helpful? Give feedback.
All reactions