perf: add opt-in precompiled headers for chain/protocol/wallet - #148
Closed
chiliec wants to merge 1 commit into
Closed
perf: add opt-in precompiled headers for chain/protocol/wallet#148chiliec wants to merge 1 commit into
chiliec wants to merge 1 commit into
Conversation
Introduces target_precompile_headers for the three heaviest libraries, gated behind a new ENABLE_PCH option (default OFF). CMake 3.16+ (already the minimum) supports PCH natively; nothing used it before, so every translation unit re-parsed the same large Boost.MultiIndex / FC reflection / std headers. Each library gets a pch.hpp listing only *stable* third-party headers, chosen from an include-frequency scan of that library's sources: - chain -> Boost.MultiIndex containers + FC serialization/reflection - protocol -> FC reflection / static_variant + operation machinery - wallet -> Boost.MultiIndex, Boost string/range, FC api Project headers are deliberately excluded: a churning header in the PCH would force a full-library rebuild on every edit and defeat the purpose. Default OFF so it cannot affect existing or CI builds until a maintainer opts in and measures. ccache interaction is handled: when ENABLE_PCH is ON and ccache is active but CCACHE_SLOPPINESS lacks pch_defines,time_macros, CMake emits a warning (ccache otherwise disables its own cache for PCH TUs). Validation (no Boost/submodules available in my env, so full tree build not run): - Real cmake executes the ENABLE_PCH block correctly: OFF prints a silent status, ON prints status + the ccache warning only when sloppiness is unset. - The target_precompile_headers wiring itself was proven on a standalone cmake project mimicking the same shape (24 TUs sharing a heavy header set): a single-threaded build went 16.84s -> 5.73s (2.9x) with a real .pch artifact produced. std headers stand in for Boost here; Boost.MultiIndex/FC parse costs are at least as high, so this is a conservative proxy. Usage: cmake -S . -B build -DENABLE_PCH=ON # if using ccache: export CCACHE_SLOPPINESS=pch_defines,time_macros
On1x
added a commit
that referenced
this pull request
Aug 11, 2026
Member
|
Folded into the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds precompiled-header (PCH) support for the three heaviest libraries, gated behind a new
ENABLE_PCHoption (default OFF). No source code touched.Motivation
cmake_minimum_requiredis already 3.16, which has nativetarget_precompile_headers, but nothing used it. Every translation unit inchain,protocol, andwalletre-parsed the same large template-heavy third-party headers from scratch. An include-frequency scan of each library's sources shows the cost concentrated in:multi_index_container,ordered_index,hashed_index,composite_key) + FC serialization/reflectionstatic_variant+ the operation type machineryapi/reflectionWhat this does
libraries/{chain,protocol,wallet}/pch.hpp, each listing only stable third-party headers (Boost, FC, std). Project headers are deliberately excluded — a churning header in the PCH would force a full-library rebuild on every edit and defeat the purpose.target_precompile_headers(<lib> PRIVATE pch.hpp)in each library, wrapped inif(ENABLE_PCH).option(ENABLE_PCH ... OFF).Safety
ENABLE_PCH=ON, ccache is active, andCCACHE_SLOPPINESSlackspch_defines,time_macros, CMake emits a warning (otherwise ccache silently disables its cache for PCH TUs — you'd lose the ccache win without gaining the PCH one).Usage
Validation
I don't have Boost dev libs or the submodules in my environment, so a full tree build wasn't possible. What I did verify with real
cmake:ENABLE_PCHlogic executes correctly: OFF prints a silent status line; ON prints status and the ccache warning only whenCCACHE_SLOPPINESSis unset; ON + sloppiness is clean.target_precompile_headerswiring itself was proven end-to-end on a standalone CMake project mimicking the same shape — 24 TUs sharing one heavy header set. Single-threaded build: 16.84s → 5.73s (2.9×), with a real.pchartifact produced. (std headers stand in for Boost there; Boost.MultiIndex + FC reflection parse costs are at least as high, so this is a conservative proxy — not a measurement of this repo's actual numbers.)Ask for the maintainer: run a real before/after on a build box —
and confirm the win holds on this codebase before considering flipping the default.