meson: Further optimize compile times with PCH template instantiations#13519
Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom Jul 22, 2025
Merged
meson: Further optimize compile times with PCH template instantiations#13519Ericson2314 merged 1 commit intoNixOS:masterfrom
Ericson2314 merged 1 commit intoNixOS:masterfrom
Conversation
This is a follow-up to 6ec50ba, which also almost halves the compile times on clang for subprojects that use PCH. `-fpch-instantiate-templates` is a clang-only option to force the instantiation of templates once in the PCH itself, not all of the translation units that it gets included to. This really cuts down on the overhead from nlohmann::json and std::format code: 48244 ms: nlohmann::basic_json<>::parse<const char *> (76 times, avg 634 ms) 36193 ms: nlohmann::basic_json<>::basic_json (310 times, avg 116 ms) 28307 ms: nlohmann::detail::parser<nlohmann::basic_json<>, nlohmann::detail::i... (76 times, avg 372 ms) 20334 ms: nlohmann::detail::parser<nlohmann::basic_json<>, nlohmann::detail::i... (76 times, avg 267 ms) 17387 ms: nlohmann::basic_json<>::json_value::json_value (389 times, avg 44 ms) 16822 ms: std::vformat_to<std::__format::_Sink_iter<char>> (76 times, avg 221 ms) 16771 ms: std::__format::__do_vformat_to<std::__format::_Sink_iter<char>, char... (76 times, avg 220 ms) 12160 ms: std::vformat_to<std::__format::_Sink_iter<wchar_t>> (76 times, avg 160 ms) 12127 ms: std::__format::__do_vformat_to<std::__format::_Sink_iter<wchar_t>, w... (76 times, avg 159 ms) 10397 ms: nlohmann::detail::json_sax_dom_callback_parser<nlohmann::basic_json<... (76 times, avg 136 ms) 9118 ms: nlohmann::basic_json<>::data::data (76 times, avg 119 ms) Initially done by Jade Lovelace <lix@jade.fyi> in https://gerrit.lix.systems/c/lix/+/1842. We are doing basically the same, but unconditionally. It would be a huge pain to add a pch option for all subprojects to just support the usecase of using clangd in a gcc devshell. In total, this basically halves the frontend times for nix-util and nix-store to the point that the most expensive part of the build is linking. (nix-store before): ``` **** Time summary: Compilation (77 times): Parsing (frontend): 243.4 s Codegen & opts (backend): 140.3 s ``` (nix-store after): ``` **** Time summary: Compilation (77 times): Parsing (frontend): 120.2 s Codegen & opts (backend): 141.2 s ```
Ericson2314
approved these changes
Jul 22, 2025
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.
Motivation
This is a follow-up to 6ec50ba, which also almost halves the compile times on clang for subprojects that use PCH.
-fpch-instantiate-templatesis a clang-only option to force the instantiation of templates once in the PCH itself, not all of the translation units that it gets included to. This really cuts down on the overhead from nlohmann::json and std::format code:Initially done by Jade Lovelace lix@jade.fyi in https://gerrit.lix.systems/c/lix/+/1842. We are doing basically the same, but unconditionally. It would be a huge pain to add a pch option for all subprojects to just support the usecase of using clangd in a gcc devshell.
In total, this basically halves the frontend times for nix-util and nix-store to the point that the most expensive part of the build is linking.
(nix-store before):
(nix-store after):
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.