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

Re: [PATCH v2] Makefile: let ccache cache objects built with the precompiled header

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Dec 3, 2026, 11:04 UTC
Message-ID
<0db82cc0-9048-4970-b780-73156710ee5a@gmail.com>
In-Reply-To
<pull.2464.v2.git.git.1793262816420.gitgitgadget@gmail.com>
Hi Harald
On 29/10/2026 08:33, Harald Nordgren via GitGitGadget wrote:
Show 7 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com>
> > Since 8d3a673147 (Makefile: precompile "git-compat-util.h",
> 2026-09-15), rebuilding Git with ccache is almost as slow as building
> it without. ccache refuses to cache a compilation that uses a
> precompiled header unless its "pch_defines" and "time_macros"
> sloppiness is enabled, so it runs the compiler for nearly every object
> file, even after a "make clean" in a tree it has already built.
While I use ccache, I've always just used the builtin defaults, so I was hoping someone with more experience would review this but that hasn't happened. What you've written agrees with the ccache man page. One thing I don't quite understand is that the manual also says "without proper setup, ccache falls back to the non-precompiled header (if available)." yet we're seeing it rebuild everything instead.
Show 7 quoted lines
> Both settings are safe for our build. The precompiled header is only
> pulled in with "-include" ahead of the source file, so no "#define" in
> a source file can come before it, and none of our sources use
> __DATE__, __TIME__ or __TIMESTAMP__.
> > Enable them whenever we build with the precompiled header.
> On my machine, "make clean && make -j8" with a warm cache goes from
> about 100 seconds to under 30.
I tested this patch with gcc and see the same. The cache is also used when switching to a different branch and back again.
> With Clang, switching to a branch that changes one of the headers the
> precompiled header includes and back again still misses the cache,
> because Clang records the modification times of those headers in the
> precompiled header.
That's a pain, the ccache manual mentions using -fno-pch-timestamp - should we be adding that as well?
Thanks for working on this
Phillip
Show 50 quoted lines
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>      Makefile: let ccache cache objects built with the precompiled header
>      >      With ccache, building after switching between two feature branches gets
>      about 6 times faster. The first build of each branch gets about 25%
>      slower while ccache fills its cache.
>      >      Changes in v2:
>      >       * Move the CCACHE_SLOPPINESS export from the precompiled header targets
>         into the ifndef NO_PRECOMPILED_HEADER block.
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2464%2FHaraldNordgren%2Fmakefile-ccache-pch-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2464/HaraldNordgren/makefile-ccache-pch-v2
> Pull-Request: https://github.com/git/git/pull/2464
> > Range-diff vs v1:
> >   1:  1984b13246 ! 1:  e61cca8cca Makefile: let ccache cache objects built with the precompiled header
>       @@ Commit message
>            a source file can come before it, and none of our sources use
>            __DATE__, __TIME__ or __TIMESTAMP__.
>        >       -    Enable them for the precompiled header and the objects built with it.
>       +    Enable them whenever we build with the precompiled header.
>            On my machine, "make clean && make -j8" with a warm cache goes from
>            about 100 seconds to under 30.
>        >       @@ Commit message
>            Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
>        >         ## Makefile ##
>       -@@ Makefile: $(PRECOMPILED_HEADER_GCH): %.gch: % GIT-CFLAGS $(missing_dep_dirs) $(missing_com
>       - $(PRECOMPILED_HEADER_USERS): %.o: %.c $(PRECOMPILED_HEADER_GCH) GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)
>       - 	$(QUIET_CC)$(CC) -o $*.o -c -include $(PRECOMPILED_HEADER) -Winvalid-pch $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
>       +@@ Makefile: PRECOMPILED_HEADER_GCH := $(addsuffix .gch,$(PRECOMPILED_HEADER))
>         >       -+$(PRECOMPILED_HEADER_GCH) $(PRECOMPILED_HEADER_USERS): export CCACHE_SLOPPINESS += pch_defines,time_macros
>       -+
>       - $(filter-out $(PRECOMPILED_HEADER_USERS),$(OBJECTS)): %.o: %.c GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)
>       - 	$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
>       + ifndef NO_PRECOMPILED_HEADER
>       + PRECOMPILED_HEADER_USERS := $(filter-out $(COMPAT_OBJS) $(REFTABLE_OBJS) $(patsubst %.c,%.o,$(THIRD_PARTY_SOURCES)),$(OBJECTS))
>       ++export CCACHE_SLOPPINESS += pch_defines,time_macros
>       + endif
>         >       + dep_files := $(foreach f,$(OBJECTS) $(PRECOMPILED_HEADER_GCH),$(dir $f).depend/$(notdir $f).d)
> > >   Makefile | 1 +
>   1 file changed, 1 insertion(+)
> > diff --git a/Makefile b/Makefile
> index a96be506b5..80653bb22c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2903,6 +2903,7 @@ PRECOMPILED_HEADER_GCH := $(addsuffix .gch,$(PRECOMPILED_HEADER))
>   >   ifndef NO_PRECOMPILED_HEADER
>   PRECOMPILED_HEADER_USERS := $(filter-out $(COMPAT_OBJS) $(REFTABLE_OBJS) $(patsubst %.c,%.o,$(THIRD_PARTY_SOURCES)),$(OBJECTS))
> +export CCACHE_SLOPPINESS += pch_defines,time_macros
>   endif
>   >   dep_files := $(foreach f,$(OBJECTS) $(PRECOMPILED_HEADER_GCH),$(dir $f).depend/$(notdir $f).d)
> > base-commit: 37b3475fb530c14109211faca33716a173db61ed
Previous: Harald Nordgren via GitGitGadgetNext: Harald Nordgren
Message 9 of 10 in “Makefile: let ccache cache objects built with the precompiled header”
  1. Makefile: let ccache cache objects built with the precompiled headerHarald Nordgren via GitGitGadget, Oct 27, 2026
  2. Ben KnobleOct 27, 2026
  3. Harald NordgrenOct 27, 2026
  4. D. Ben KnobleOct 27, 2026
  5. Patrick SteinhardtOct 28, 2026
  6. Harald NordgrenOct 28, 2026
  7. Harald NordgrenOct 30, 2026
  8. Makefile: let ccache cache objects built with the precompiled headerHarald Nordgren via GitGitGadget, Oct 29, 2026
  9. Phillip WoodDec 3, 2026
  10. Harald NordgrenDec 3, 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.