From 3c0a5e0a5101a21626394985f394cd1a273a6f94 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 17 Aug 2025 00:56:41 +0300 Subject: [PATCH 1/5] nix-cli: Improve compile times (Before) **** Time summary: Compilation (61 times): Parsing (frontend): 143.2 s Codegen & opts (backend): 105.8 s (After) **** Time summary: Compilation (61 times): Parsing (frontend): 113.8 s Codegen & opts (backend): 111.7 s --- src/nix/pch/precompiled-headers.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/nix/pch/precompiled-headers.hh b/src/nix/pch/precompiled-headers.hh index 5b320c861..ab5856ea8 100644 --- a/src/nix/pch/precompiled-headers.hh +++ b/src/nix/pch/precompiled-headers.hh @@ -1,3 +1,6 @@ #include "nix/cmd/command.hh" #include "nix/expr/eval.hh" #include "nix/main/shared.hh" +#include "nix/store/derivations.hh" + +#include From d6973e105cdd5a39150c9d95d851e2d3b9db67c4 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 17 Aug 2025 00:56:54 +0300 Subject: [PATCH 2/5] libexpr-tests: Improve compile times with PCH (Before) **** Time summary: Compilation (14 times): Parsing (frontend): 60.1 s Codegen & opts (backend): 18.0 s (After) **** Time summary: Compilation (15 times): Parsing (frontend): 16.6 s Codegen & opts (backend): 17.4 s --- src/libexpr-tests/meson.build | 1 + src/libexpr-tests/pch/precompiled-headers.hh | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 src/libexpr-tests/pch/precompiled-headers.hh diff --git a/src/libexpr-tests/meson.build b/src/libexpr-tests/meson.build index 1f3973681..cc203d60e 100644 --- a/src/libexpr-tests/meson.build +++ b/src/libexpr-tests/meson.build @@ -75,6 +75,7 @@ this_exe = executable( # TODO: -lrapidcheck, see ../libutil-support/build.meson link_args : linker_export_flags + [ '-lrapidcheck' ], install : true, + cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) test( diff --git a/src/libexpr-tests/pch/precompiled-headers.hh b/src/libexpr-tests/pch/precompiled-headers.hh new file mode 100644 index 000000000..63bf023a2 --- /dev/null +++ b/src/libexpr-tests/pch/precompiled-headers.hh @@ -0,0 +1,4 @@ +#include "nix/expr/tests/libexpr.hh" + +#include +#include From f13aeaf2f1e43032454bc53d2832f01e114a9817 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 17 Aug 2025 00:57:06 +0300 Subject: [PATCH 3/5] libutil-tests: Improve compile times with PCH (Before) **** Time summary: Compilation (30 times): Parsing (frontend): 98.2 s Codegen & opts (backend): 27.7 s (After) **** Time summary: Compilation (31 times): Parsing (frontend): 34.9 s Codegen & opts (backend): 28.1 s --- src/libutil-tests/meson.build | 1 + src/libutil-tests/pch/precompiled-headers.hh | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 src/libutil-tests/pch/precompiled-headers.hh diff --git a/src/libutil-tests/meson.build b/src/libutil-tests/meson.build index e4a060d3e..6f04b46fd 100644 --- a/src/libutil-tests/meson.build +++ b/src/libutil-tests/meson.build @@ -89,6 +89,7 @@ this_exe = executable( link_args : linker_export_flags + [ '-lrapidcheck' ], # get main from gtest install : true, + cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) test( diff --git a/src/libutil-tests/pch/precompiled-headers.hh b/src/libutil-tests/pch/precompiled-headers.hh new file mode 100644 index 000000000..0a078fcc4 --- /dev/null +++ b/src/libutil-tests/pch/precompiled-headers.hh @@ -0,0 +1,5 @@ +#include "nix/util/util.hh" + +#include +#include +#include From 347ed8d9ba83b7cd45dd371c996fd9c111df91a2 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 17 Aug 2025 00:57:14 +0300 Subject: [PATCH 4/5] libfetchers: Improve compile times with PCH (Before) **** Time summary: Compilation (17 times): Parsing (frontend): 72.3 s Codegen & opts (backend): 47.8 s (After) Compilation (19 times): Parsing (frontend): 27.5 s Codegen & opts (backend): 43.8 s --- src/libfetchers/git-lfs-fetch.cc | 2 +- src/libfetchers/meson.build | 1 + src/libfetchers/pch/precompiled-headers.hh | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/libfetchers/pch/precompiled-headers.hh diff --git a/src/libfetchers/git-lfs-fetch.cc b/src/libfetchers/git-lfs-fetch.cc index 35230ae88..a68cdf832 100644 --- a/src/libfetchers/git-lfs-fetch.cc +++ b/src/libfetchers/git-lfs-fetch.cc @@ -292,7 +292,7 @@ void Fetch::fetch( auto authIt = headerIt->find("Authorization"); if (authIt == headerIt->end()) return std::nullopt; - return *authIt; + return std::string(*authIt); }(); const uint64_t size = obj.at("size"); sizeCallback(size); diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build index 0b53ef44d..3da58cb70 100644 --- a/src/libfetchers/meson.build +++ b/src/libfetchers/meson.build @@ -66,6 +66,7 @@ this_library = library( link_args : linker_export_flags, prelink : true, # For C++ static initializers install : true, + cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) install_headers(headers, subdir : 'nix/fetchers', preserve_path : true) diff --git a/src/libfetchers/pch/precompiled-headers.hh b/src/libfetchers/pch/precompiled-headers.hh new file mode 100644 index 000000000..db7f22a2e --- /dev/null +++ b/src/libfetchers/pch/precompiled-headers.hh @@ -0,0 +1,3 @@ +#include "nix/fetchers/fetchers.hh" +#include "nix/store/store-api.hh" +#include "nix/util/json-utils.hh" From 8be1cc6e96a95a634c73caf2bf545373c992b128 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 17 Aug 2025 01:08:31 +0300 Subject: [PATCH 5/5] libstore-tests: Improve compile times with PCH (Before) **** Time summary: Compilation (25 times): Parsing (frontend): 145.5 s Codegen & opts (backend): 65.9 s (After) **** Time summary: Compilation (26 times): Parsing (frontend): 39.9 s Codegen & opts (backend): 55.1 s --- src/libstore-tests/meson.build | 2 ++ src/libstore-tests/pch/precompiled-headers.hh | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 src/libstore-tests/pch/precompiled-headers.hh diff --git a/src/libstore-tests/meson.build b/src/libstore-tests/meson.build index e5995bcb1..87f6a234a 100644 --- a/src/libstore-tests/meson.build +++ b/src/libstore-tests/meson.build @@ -94,6 +94,7 @@ this_exe = executable( link_args : linker_export_flags + [ '-lrapidcheck' ], # get main from gtest install : true, + cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) test( @@ -127,6 +128,7 @@ if get_option('benchmarks') include_directories : include_dirs, link_args : linker_export_flags, install : true, + cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], cpp_args : [ '-DNIX_UNIT_TEST_DATA="' + meson.current_source_dir() + '/data"', ], diff --git a/src/libstore-tests/pch/precompiled-headers.hh b/src/libstore-tests/pch/precompiled-headers.hh new file mode 100644 index 000000000..3eaa45261 --- /dev/null +++ b/src/libstore-tests/pch/precompiled-headers.hh @@ -0,0 +1,9 @@ +#include "nix/store/store-api.hh" +#include "nix/store/tests/libstore.hh" +#include "nix/util/util.hh" + +#include +#include +#include + +#include