{"thread":{"id":"66680","subject":"[PATCH] Makefile: let ccache cache objects built with the precompiled header","startedAt":"2026-10-27T12:40:47Z","lastAt":"2026-10-30T22:26:00Z","messageCount":8,"participants":["Harald Nordgren via GitGitGadget","Ben Knoble","Harald Nordgren","D. Ben Knoble","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"556500","messageId":"pull.2464.git.git.1793104847288.gitgitgadget@gmail.com","threadId":"66680","inReplyTo":null,"subject":"[PATCH] Makefile: let ccache cache objects built with the precompiled header","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-27T12:40:47Z","receivedAt":"2026-10-27T12:40:47Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nSince 8d3a673147 (Makefile: precompile \"git-compat-util.h\",\n2026-09-15), rebuilding Git with ccache is almost as slow as building\nit without. ccache refuses to cache a compilation that uses a\nprecompiled header unless its \"pch_defines\" and \"time_macros\"\nsloppiness is enabled, so it runs the compiler for nearly every object\nfile, even after a \"make clean\" in a tree it has already built.\n\nBoth settings are safe for our build. The precompiled header is only\npulled in with \"-include\" ahead of the source file, so no \"#define\" in\na source file can come before it, and none of our sources use\n__DATE__, __TIME__ or __TIMESTAMP__.\n\nEnable them for the precompiled header and the objects built with it.\nOn my machine, \"make clean && make -j8\" with a warm cache goes from\nabout 100 seconds to under 30.\n\nWith Clang, switching to a branch that changes one of the headers the\nprecompiled header includes and back again still misses the cache,\nbecause Clang records the modification times of those headers in the\nprecompiled header.\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n    Makefile: let ccache cache objects built with the precompiled header\n    \n    With ccache, building after switching between two feature branches gets\n    about 6 times faster. The first build of each branch gets about 25%\n    slower while ccache fills its cache.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2464%2FHaraldNordgren%2Fmakefile-ccache-pch-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2464/HaraldNordgren/makefile-ccache-pch-v1\nPull-Request: https://github.com/git/git/pull/2464\n\n Makefile | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/Makefile b/Makefile\nindex a96be506b5..43ea5e0c40 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -2946,6 +2946,8 @@ $(PRECOMPILED_HEADER_GCH): %.gch: % GIT-CFLAGS $(missing_dep_dirs) $(missing_com\n $(PRECOMPILED_HEADER_USERS): %.o: %.c $(PRECOMPILED_HEADER_GCH) GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)\n \t$(QUIET_CC)$(CC) -o $*.o -c -include $(PRECOMPILED_HEADER) -Winvalid-pch $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n \n+$(PRECOMPILED_HEADER_GCH) $(PRECOMPILED_HEADER_USERS): export CCACHE_SLOPPINESS += pch_defines,time_macros\n+\n $(filter-out $(PRECOMPILED_HEADER_USERS),$(OBJECTS)): %.o: %.c GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)\n \t$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n \n\nbase-commit: 7e34d8174dcda3435d1404c9a30bef46afe6c13e\n-- \ngitgitgadget\n\n"},{"id":"556525","messageId":"579C36BA-1418-4E15-9CA7-70C752A69FCE@gmail.com","threadId":"66680","inReplyTo":"pull.2464.git.git.1793104847288.gitgitgadget@gmail.com","subject":"Re: [PATCH] Makefile: let ccache cache objects built with the precompiled header","fromName":"Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-27T15:58:50Z","receivedAt":"2026-10-27T15:58:50Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"\n> Le 27 oct. 2026 à 08:49, Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com> a écrit :\n> \n> ﻿From: Harald Nordgren <haraldnordgren@gmail.com>\n> \n> Since 8d3a673147 (Makefile: precompile \"git-compat-util.h\",\n> 2026-09-15), rebuilding Git with ccache is almost as slow as building\n> it without. ccache refuses to cache a compilation that uses a\n> precompiled header unless its \"pch_defines\" and \"time_macros\"\n> sloppiness is enabled, so it runs the compiler for nearly every object\n> file, even after a \"make clean\" in a tree it has already built.\n> \n> Both settings are safe for our build. The precompiled header is only\n> pulled in with \"-include\" ahead of the source file, so no \"#define\" in\n> a source file can come before it, and none of our sources use\n> __DATE__, __TIME__ or __TIMESTAMP__.\n> \n> Enable them for the precompiled header and the objects built with it.\n> On my machine, \"make clean && make -j8\" with a warm cache goes from\n> about 100 seconds to under 30.\n> \n> With Clang, switching to a branch that changes one of the headers the\n> precompiled header includes and back again still misses the cache,\n> because Clang records the modification times of those headers in the\n> precompiled header.\n> \n> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n> ---\n>    Makefile: let ccache cache objects built with the precompiled header\n> \n>    With ccache, building after switching between two feature branches gets\n>    about 6 times faster. The first build of each branch gets about 25%\n>    slower while ccache fills its cache.\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2464%2FHaraldNordgren%2Fmakefile-ccache-pch-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2464/HaraldNordgren/makefile-ccache-pch-v1\n> Pull-Request: https://github.com/git/git/pull/2464\n\nI can’t comment on the above, not being a ccache user myself.\n\n> Makefile | 2 ++\n> 1 file changed, 2 insertions(+)\n> \n> diff --git a/Makefile b/Makefile\n> index a96be506b5..43ea5e0c40 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -2946,6 +2946,8 @@ $(PRECOMPILED_HEADER_GCH): %.gch: % GIT-CFLAGS $(missing_dep_dirs) $(missing_com\n> $(PRECOMPILED_HEADER_USERS): %.o: %.c $(PRECOMPILED_HEADER_GCH) GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)\n>    $(QUIET_CC)$(CC) -o $*.o -c -include $(PRECOMPILED_HEADER) -Winvalid-pch $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n> \n> +$(PRECOMPILED_HEADER_GCH) $(PRECOMPILED_HEADER_USERS): export CCACHE_SLOPPINESS += pch_defines,time_macros\n> +\n\nThis is a little curious to me. I’m familiar with the GNU Make-ism \nto set variables for particular targets; how does the export work?\nIs it the same but with a propagation to the recipe processes?\n\nWould it be better (for some definition…) to put the export in the 2\npre-compiled header recipes directly?\n\nAnd, what about Meson?\n"},{"id":"556573","messageId":"CAHwyqnX3sR9YxfK3NtPxVgmTfzfbgXX2bzPKzGGAbfC9k1iF4A@mail.gmail.com","threadId":"66680","inReplyTo":"579C36BA-1418-4E15-9CA7-70C752A69FCE@gmail.com","subject":"Re: [PATCH] Makefile: let ccache cache objects built with the precompiled header","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-27T20:00:13Z","receivedAt":"2026-10-27T20:00:13Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> > @@ -2946,6 +2946,8 @@ $(PRECOMPILED_HEADER_GCH): %.gch: % GIT-CFLAGS $(missing_dep_dirs) $(missing_com\n> > $(PRECOMPILED_HEADER_USERS): %.o: %.c $(PRECOMPILED_HEADER_GCH) GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)\n> >    $(QUIET_CC)$(CC) -o $*.o -c -include $(PRECOMPILED_HEADER) -Winvalid-pch $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n> >\n> > +$(PRECOMPILED_HEADER_GCH) $(PRECOMPILED_HEADER_USERS): export CCACHE_SLOPPINESS += pch_defines,time_macros\n> > +\n>\n> This is a little curious to me. I’m familiar with the GNU Make-ism\n> to set variables for particular targets; how does the export work?\n> Is it the same but with a propagation to the recipe processes?\n>\n> Would it be better (for some definition…) to put the export in the 2\n> pre-compiled header recipes directly?\n\nYeah, that could be a good idea.\n\n> And, what about Meson?\n\nI think it's not touched by this? My goal is just to speed up my local builds.\n\n\nHarald\n\n"},{"id":"556585","messageId":"CALnO6CDpsQtAX0rHr9Cuot08K4j_6WMpiPOKA38sjDbWB-wj7A@mail.gmail.com","threadId":"66680","inReplyTo":"CAHwyqnX3sR9YxfK3NtPxVgmTfzfbgXX2bzPKzGGAbfC9k1iF4A@mail.gmail.com","subject":"Re: [PATCH] Makefile: let ccache cache objects built with the precompiled header","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-27T21:57:38Z","receivedAt":"2026-10-27T21:57:38Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Tue, Oct 27, 2026 at 4:00 PM Harald Nordgren\n<haraldnordgren@gmail.com> wrote:\n>\n> > And, what about Meson?\n>\n> I think it's not touched by this? My goal is just to speed up my local builds.\n\nYeah, it'd generally be nice to keep the 2 on par though ;)\n\nI don't know enough about our pch infra, though, so I'll bow out from\nhere. Just thought maybe we should make Meson do the same?\n\n-- \nD. Ben Knoble\n\n"},{"id":"556614","messageId":"auGln4usFADtcUPB@pks.im","threadId":"66680","inReplyTo":"CALnO6CDpsQtAX0rHr9Cuot08K4j_6WMpiPOKA38sjDbWB-wj7A@mail.gmail.com","subject":"Re: [PATCH] Makefile: let ccache cache objects built with the precompiled header","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T07:34:55Z","receivedAt":"2026-10-28T07:34:55Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Oct 27, 2026 at 05:57:38PM -0400, D. Ben Knoble wrote:\n> On Tue, Oct 27, 2026 at 4:00 PM Harald Nordgren\n> <haraldnordgren@gmail.com> wrote:\n> >\n> > > And, what about Meson?\n> >\n> > I think it's not touched by this? My goal is just to speed up my local builds.\n> \n> Yeah, it'd generally be nice to keep the 2 on par though ;)\n> \n> I don't know enough about our pch infra, though, so I'll bow out from\n> here. Just thought maybe we should make Meson do the same?\n\nAs Meson auto-detects ccache I'd think that stuff like this should\nrather be handled in Meson itself. I e.g. found [1], which feels like\nthe right direction to me.\n\nBut if somebody wants to implement this in our instructions meanwhile I\nwon't complain.\n\nPatrick\n\n[1]: https://github.com/mesonbuild/meson/issues/14662\n\n"},{"id":"556630","messageId":"CAHwyqnW8kx7BmGq99twGfC2ZB0u0sj17345dcyZ7sxw8A4ZZaA@mail.gmail.com","threadId":"66680","inReplyTo":"auGln4usFADtcUPB@pks.im","subject":"Re: [PATCH] Makefile: let ccache cache objects built with the precompiled header","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-28T09:58:26Z","receivedAt":"2026-10-28T09:58:26Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> > > > And, what about Meson?\n> > >\n> > > I think it's not touched by this? My goal is just to speed up my local builds.\n> >\n> > Yeah, it'd generally be nice to keep the 2 on par though ;)\n> >\n> > I don't know enough about our pch infra, though, so I'll bow out from\n> > here. Just thought maybe we should make Meson do the same?\n>\n> As Meson auto-detects ccache I'd think that stuff like this should\n> rather be handled in Meson itself. I e.g. found [1], which feels like\n> the right direction to me.\n>\n> But if somebody wants to implement this in our instructions meanwhile I\n> won't complain.\n>\n> Patrick\n>\n> [1]: https://github.com/mesonbuild/meson/issues/14662\n\nOk, so I'll leave Meson out of this. Maybe I'll look into opening a PR\nthere instead.\n\n\nHarald\n\n"},{"id":"556740","messageId":"pull.2464.v2.git.git.1793262816420.gitgitgadget@gmail.com","threadId":"66680","inReplyTo":"pull.2464.git.git.1793104847288.gitgitgadget@gmail.com","subject":"[PATCH v2] Makefile: let ccache cache objects built with the precompiled header","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-29T08:33:36Z","receivedAt":"2026-10-29T08:33:36Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nSince 8d3a673147 (Makefile: precompile \"git-compat-util.h\",\n2026-09-15), rebuilding Git with ccache is almost as slow as building\nit without. ccache refuses to cache a compilation that uses a\nprecompiled header unless its \"pch_defines\" and \"time_macros\"\nsloppiness is enabled, so it runs the compiler for nearly every object\nfile, even after a \"make clean\" in a tree it has already built.\n\nBoth settings are safe for our build. The precompiled header is only\npulled in with \"-include\" ahead of the source file, so no \"#define\" in\na source file can come before it, and none of our sources use\n__DATE__, __TIME__ or __TIMESTAMP__.\n\nEnable them whenever we build with the precompiled header.\nOn my machine, \"make clean && make -j8\" with a warm cache goes from\nabout 100 seconds to under 30.\n\nWith Clang, switching to a branch that changes one of the headers the\nprecompiled header includes and back again still misses the cache,\nbecause Clang records the modification times of those headers in the\nprecompiled header.\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n    Makefile: let ccache cache objects built with the precompiled header\n    \n    With ccache, building after switching between two feature branches gets\n    about 6 times faster. The first build of each branch gets about 25%\n    slower while ccache fills its cache.\n    \n    Changes in v2:\n    \n     * Move the CCACHE_SLOPPINESS export from the precompiled header targets\n       into the ifndef NO_PRECOMPILED_HEADER block.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2464%2FHaraldNordgren%2Fmakefile-ccache-pch-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2464/HaraldNordgren/makefile-ccache-pch-v2\nPull-Request: https://github.com/git/git/pull/2464\n\nRange-diff vs v1:\n\n 1:  1984b13246 ! 1:  e61cca8cca Makefile: let ccache cache objects built with the precompiled header\n     @@ Commit message\n          a source file can come before it, and none of our sources use\n          __DATE__, __TIME__ or __TIMESTAMP__.\n      \n     -    Enable them for the precompiled header and the objects built with it.\n     +    Enable them whenever we build with the precompiled header.\n          On my machine, \"make clean && make -j8\" with a warm cache goes from\n          about 100 seconds to under 30.\n      \n     @@ Commit message\n          Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n      \n       ## Makefile ##\n     -@@ Makefile: $(PRECOMPILED_HEADER_GCH): %.gch: % GIT-CFLAGS $(missing_dep_dirs) $(missing_com\n     - $(PRECOMPILED_HEADER_USERS): %.o: %.c $(PRECOMPILED_HEADER_GCH) GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)\n     - \t$(QUIET_CC)$(CC) -o $*.o -c -include $(PRECOMPILED_HEADER) -Winvalid-pch $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n     +@@ Makefile: PRECOMPILED_HEADER_GCH := $(addsuffix .gch,$(PRECOMPILED_HEADER))\n       \n     -+$(PRECOMPILED_HEADER_GCH) $(PRECOMPILED_HEADER_USERS): export CCACHE_SLOPPINESS += pch_defines,time_macros\n     -+\n     - $(filter-out $(PRECOMPILED_HEADER_USERS),$(OBJECTS)): %.o: %.c GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)\n     - \t$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<\n     + ifndef NO_PRECOMPILED_HEADER\n     + PRECOMPILED_HEADER_USERS := $(filter-out $(COMPAT_OBJS) $(REFTABLE_OBJS) $(patsubst %.c,%.o,$(THIRD_PARTY_SOURCES)),$(OBJECTS))\n     ++export CCACHE_SLOPPINESS += pch_defines,time_macros\n     + endif\n       \n     + dep_files := $(foreach f,$(OBJECTS) $(PRECOMPILED_HEADER_GCH),$(dir $f).depend/$(notdir $f).d)\n\n\n Makefile | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/Makefile b/Makefile\nindex a96be506b5..80653bb22c 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -2903,6 +2903,7 @@ PRECOMPILED_HEADER_GCH := $(addsuffix .gch,$(PRECOMPILED_HEADER))\n \n ifndef NO_PRECOMPILED_HEADER\n PRECOMPILED_HEADER_USERS := $(filter-out $(COMPAT_OBJS) $(REFTABLE_OBJS) $(patsubst %.c,%.o,$(THIRD_PARTY_SOURCES)),$(OBJECTS))\n+export CCACHE_SLOPPINESS += pch_defines,time_macros\n endif\n \n dep_files := $(foreach f,$(OBJECTS) $(PRECOMPILED_HEADER_GCH),$(dir $f).depend/$(notdir $f).d)\n\nbase-commit: 37b3475fb530c14109211faca33716a173db61ed\n-- \ngitgitgadget\n\n"},{"id":"556978","messageId":"CAHwyqnWw6VpR+4WUMEn9LOhqUyd_sGSbFUqP_p8wui2NZQOiRA@mail.gmail.com","threadId":"66680","inReplyTo":"CAHwyqnW8kx7BmGq99twGfC2ZB0u0sj17345dcyZ7sxw8A4ZZaA@mail.gmail.com","subject":"Re: [PATCH] Makefile: let ccache cache objects built with the precompiled header","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-30T22:26:00Z","receivedAt":"2026-10-30T22:26:00Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> > > > > And, what about Meson?\n> > > >\n> > > > I think it's not touched by this? My goal is just to speed up my local builds.\n> > >\n> > > Yeah, it'd generally be nice to keep the 2 on par though ;)\n> > >\n> > > I don't know enough about our pch infra, though, so I'll bow out from\n> > > here. Just thought maybe we should make Meson do the same?\n> >\n> > As Meson auto-detects ccache I'd think that stuff like this should\n> > rather be handled in Meson itself. I e.g. found [1], which feels like\n> > the right direction to me.\n> >\n> > But if somebody wants to implement this in our instructions meanwhile I\n> > won't complain.\n> >\n> > Patrick\n> >\n> > [1]: https://github.com/mesonbuild/meson/issues/14662\n>\n> Ok, so I'll leave Meson out of this. Maybe I'll look into opening a PR\n> there instead.\n\nThis has now been merged into Meson:\nhttps://github.com/mesonbuild/meson/pull/16317\n\n\nHarald\n\n"}]}