git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 8/8] meson: precompile "git-compat-util.h"

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 16, 2026, 10:08 UTC
Message-ID
<20260316-b4-pks-build-infra-improvements-v2-8-4b2c2c0c0425@pks.im>
In-Reply-To
<20260316-b4-pks-build-infra-improvements-v2-0-4b2c2c0c0425@pks.im>

Every compilation unit in Git is expected to include "git-compat-util.h" first, either directly or indirectly via "builtin.h". This header papers over differences between platforms so that we can expect the typical POSIX functions to exist. Furthermore, it provides functionality that we end up using everywhere.

This header is thus quite heavy as a consequence. Preprocessing it as a standalone unit via `clang -E git-compat-util.h` yields over 23,000 lines of code overall. Naturally, it takes quite some time to compile all of this.

Luckily, this is exactly the kind of use case that precompiled headers aim to solve: instead of recompiling it every single time, we compile it once and then link the result into the executable. If include guards are set up properly it means that the file won't need to be reprocessed.

Set up such a precompiled header for "git-compat-util.h" and wire it up via Meson. This causes Meson to implicitly include the precompiled header in all compilation units. With GCC and Clang for example this is done via the "-include" statement [1].

This leads to a significant speedup when performing full builds:
  Benchmark 1: ninja (rev = HEAD~)
  Time (mean ± σ):     14.467 s ±  0.126 s    [User: 248.133 s, System: 31.298 s]
  Range (min … max):   14.195 s … 14.633 s    10 runs
  Benchmark 2: ninja (rev = HEAD)
    Time (mean ± σ):     10.307 s ±  0.111 s    [User: 173.290 s, System: 23.998 s]
    Range (min … max):   10.030 s … 10.433 s    10 runs
  Summary
    ninja (rev = HEAD) ran
      1.40 ± 0.02 times faster than ninja (rev = HEAD~)
[1]: https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 meson.build         | 2 ++
 tools/precompiled.h | 1 +
 2 files changed, 3 insertions(+)
diff --git a/meson.build b/meson.build
index cd00be1c23..2002f4795e 100644
--- a/meson.build
+++ b/meson.build
@@ -1760,6 +1760,7 @@ libgit = declare_dependency(
       c_args: libgit_c_args + [
         '-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
       ],
+      c_pch: 'tools/precompiled.h',
       dependencies: libgit_dependencies,
       include_directories: libgit_include_directories,
     ),
@@ -1820,6 +1821,7 @@ test_dependencies = [ ]
 
 git_builtin = executable('git',
   sources: builtin_sources + 'git.c',
+  c_pch: 'tools/precompiled.h',
   dependencies: [libgit_commonmain],
   install: true,
   install_dir: git_exec_path,
diff --git a/tools/precompiled.h b/tools/precompiled.h
new file mode 100644
index 0000000000..b2bec0d2b4
--- /dev/null
+++ b/tools/precompiled.h
@@ -0,0 +1 @@
+#include "git-compat-util.h"
-- 
2.53.0.959.g497ff81fa9.dirty
Previous: Patrick SteinhardtNext: Phillip Wood
Message 37 of 53 in “Some build system improvements”
  1. 0/8 Some build system improvementsPatrick Steinhardt, Mar 10, 2026
  2. 1/8 Introduce new "tools/" directoryPatrick Steinhardt, Mar 10, 2026
  3. 2/8 contrib: move "coccinelle/" directory into "tools/"Patrick Steinhardt, Mar 10, 2026
  4. 3/8 contrib: move "coverage-diff.sh" script into "tools/"Patrick Steinhardt, Mar 10, 2026
  5. 4/8 contrib: move "update-unicode.sh" script into "tools/"Patrick Steinhardt, Mar 10, 2026
  6. 5/8 builds: move build scripts into "tools/"Patrick Steinhardt, Mar 10, 2026
  7. 6/8 git-compat-util.h: move warning infra to prepare for PCHsPatrick Steinhardt, Mar 10, 2026
  8. 7/8 meson: compile compatibility sources separatelyPatrick Steinhardt, Mar 10, 2026
  9. Phillip WoodMar 11, 2026
  10. Phillip WoodMar 11, 2026
  11. SZEDER GáborMar 11, 2026
  12. Patrick SteinhardtMar 12, 2026
  13. Phillip WoodMar 13, 2026
  14. Patrick SteinhardtMar 16, 2026
  15. SZEDER GáborApr 10, 2026
  16. Patrick SteinhardtMar 12, 2026
  17. Phillip WoodMar 13, 2026
  18. Patrick SteinhardtMar 16, 2026
  19. Phillip WoodMar 16, 2026
  20. Kristoffer HaugsbakkMar 17, 2026
  21. Patrick SteinhardtMar 19, 2026
  22. 8/8 meson: precompile "git-compat-util.h"Patrick Steinhardt, Mar 10, 2026
  23. Phillip WoodMar 11, 2026
  24. Patrick SteinhardtMar 12, 2026
  25. Junio C HamanoMar 10, 2026
  26. Patrick SteinhardtMar 11, 2026
  27. Junio C HamanoMar 13, 2026
  28. Patrick SteinhardtMar 16, 2026
  29. 0/8 Some build system improvementsPatrick Steinhardt, Mar 16, 2026
  30. 1/8 Introduce new "tools/" directoryPatrick Steinhardt, Mar 16, 2026
  31. 2/8 contrib: move "coccinelle/" directory into "tools/"Patrick Steinhardt, Mar 16, 2026
  32. 3/8 contrib: move "coverage-diff.sh" script into "tools/"Patrick Steinhardt, Mar 16, 2026
  33. 4/8 contrib: move "update-unicode.sh" script into "tools/"Patrick Steinhardt, Mar 16, 2026
  34. 5/8 builds: move build scripts into "tools/"Patrick Steinhardt, Mar 16, 2026
  35. 6/8 git-compat-util.h: move warning infra to prepare for PCHsPatrick Steinhardt, Mar 16, 2026
  36. 7/8 meson: compile compatibility sources separatelyPatrick Steinhardt, Mar 16, 2026
  37. 8/8 meson: precompile "git-compat-util.h"Patrick Steinhardt, Mar 16, 2026
  38. Phillip WoodMar 16, 2026
  39. 0/8 Some build system improvementsPatrick Steinhardt, Mar 19, 2026
  40. 1/8 Introduce new "tools/" directoryPatrick Steinhardt, Mar 19, 2026
  41. 2/8 contrib: move "coccinelle/" directory into "tools/"Patrick Steinhardt, Mar 19, 2026
  42. 3/8 contrib: move "coverage-diff.sh" script into "tools/"Patrick Steinhardt, Mar 19, 2026
  43. Toon ClaesMar 20, 2026
  44. 4/8 contrib: move "update-unicode.sh" script into "tools/"Patrick Steinhardt, Mar 19, 2026
  45. 5/8 builds: move build scripts into "tools/"Patrick Steinhardt, Mar 19, 2026
  46. 6/8 git-compat-util.h: move warning infra to prepare for PCHsPatrick Steinhardt, Mar 19, 2026
  47. Toon ClaesMar 20, 2026
  48. 7/8 meson: compile compatibility sources separatelyPatrick Steinhardt, Mar 19, 2026
  49. 8/8 meson: precompile "git-compat-util.h"Patrick Steinhardt, Mar 19, 2026
  50. Toon ClaesMar 20, 2026
  51. SZEDER GáborApr 10, 2026
  52. Phillip WoodApr 10, 2026
  53. SZEDER GáborApr 10, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.