From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796295896; b=xOAYLb80rnecxPolQqyOoCyCfVb6l4sOJ5A3kQvf7A/BKZ5Xe8x3OFiKJBTSqXp65prX XwGzuy+GbXdPxxsyyh1seRzkb4d7Tk6M5O3lN+hwn0BxDET5IjH9YLa8rmT+RZmYnSPp4 z4ZDMO7QLKIZN6yJrk/J3U5r5H1OXsYBSd8SkwiFJsbARz5GIWsQppAyLWNigCTQR7dCU SaCJhzEf6i3Weh0xiLNAzNwAx0UVI3Pyd7Ot7Tiyj5DO8pPm2aXEXbWOXspXZLcQ1xZXU Ww14+742+AAck8c9tPg2EGLurem0xx42XOoDucCSf3boJKrkqc9O8rF8WXLcQvBG9RQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796295896; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Reply-To:Subject:To:Cc: References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=fJ89kopkY8D+LtpVdzhr+Z26Cs5fEV+vsf3n4B933k4=; b=Y1gsWAYT5vULjZ+MeUnxkuYLbZeoP2aaJu6d01YGfJRLMZGpVqmUS4CjW2T1BUBNPoYL 4u0X08Uk8ZlamGE28fq0GjUCkTwWJBS+1t9idoQjv0HATSPcKW2fD3EQ4lRPRckVF2anZ RGtHPGZ0A4NSdchZ6GI21aMbnim0FjdvWuCl9xeID/Sv9EZ/nNkOd6yXnxSIVsUy8LGpD 9yLcZXqzL53OCg3+AuVKgYeDIGi3r+SDpdM1rm3pKwGsx1LrvlkZCYArsOlOa+hO5V5So QjVwbQmqdNHp5lRCNtpE3RktFGtbs1AhMYoPZL501isa8vdQNAEmU45OmCQYG9FOIuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=gxJYiV4d; arc=none smtp.remote-ip=209.85.221.44 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 163FA606A32C for ; Thu, 3 Dec 2026 11:04:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 163FA606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=gxJYiV4d Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-4c84abcb7bdso2273451f8f.1 for ; Thu, 03 Dec 2026 03:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796295894; x=1796900694; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:reply-to:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=fJ89kopkY8D+LtpVdzhr+Z26Cs5fEV+vsf3n4B933k4=; b=gxJYiV4dFf28hhIDltPClFhMO5aN3zHliJapwQKZrREeMgWmQJxkneiBkzjyQnv/2j dbuQg1geZxpkMkvz/a0zZABrmmNu1XvPWJxjANE9e4GE1KM3lSV3b/iEUMoIGoiefL0f FNDgoB/2KLrxy/mT6UZtAB0Pjd88QwjmTeVhZU/2F9Jw0p4oLHV5/CsIz01rYH8S99JX CZ7zDyNQTYW4PIk/9Lbbpex7ndR7pPSvb36ewlbrhNOM/Xd9aN4qIuVdsMi9IR+0ZEqG 3XqSw4080tpMziJToKVMAT9v46TANBL5SN/aooWYdDMpQe6pmUow/l5UavnL1P8h/ZZT opmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796295894; x=1796900694; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:reply-to:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=fJ89kopkY8D+LtpVdzhr+Z26Cs5fEV+vsf3n4B933k4=; b=MXfReo1TnQ5GY/tFtmpnZ+gU53vUuqORGtpDztFYLjNnjc12vMN+ly8SMNCQtuyBYl uFGmSoAcvoleG9rPrVr69EMrwgMPcPSr8zq1qSx56DP4vp43jjt1WXiJeDuBLklX30lq C9C7Ia5WQcut5AN0Ro4Fv04ktkv3VRDRajcm5goVMd8tQosqU8+SUgd9j1FrmwVrreuG fAAyBDYVzIVgpkMzTj20+NYVfFxS+yDUTd3A8MXzcZNEOv1XLPGQ6euk1eWm+ks+RzE+ J6T7JZ4sjPzQQxEqIi8YDZANhk92UgNiDku2swpoS/ts65VMsSPsxLl3QWr4xliRYqb8 f8hg== X-Forwarded-Encrypted: i=1; AL+hErGGVavxB/dOpDf1YFvVOCaolJDBSfcx6c3S99aS0wCyC0CQo2d5KWhUhAAEjTL+awdFP78=@vger.kernel.org X-Gm-Message-State: APuU4Z8xhHkYcqRu89qlMVZ9i+XKno7LvW54uxGvaEB4YI8zj99TdwCF wUWOLxF6LFejqlAsKUp2zVmQcucxXTAkyXmojOJLcNCvpPMttTqQKzFP X-Gm-Gg: AZFdTZcdeMfz0/rPvzgLmSO5M5F5BgtN31iBudMbrFcBt6bqNv9dQGOWxlJ6zcy5pa0 A2E3QqIGl5EZkTAb0WPxjiHpkgdXOd6VZqJDYKDFV+sTQdPioRwsLj2/wJUJMTvm5F7+aAPatKr a3CDbf+ulkxE2N36g5nPj/UnAgFN3OqP3DFr2BZxz+XGla8P4Qo/IWyl+UYQU2LkJXhLeXMHHBL nDXYia/VymVUhQLn+BZdiBfR+gxKjTVYSONSpjavNzOyWhyFSbt5daHUwsYLYEYs0rx2fjEBGIs D0hIrJQNKlIw9SoV8l/uItY2YSKWjOgINkVvjo5F7iSY+PXVhnyWT0kaoJOigoVoIBrW018n2ZQ /oQDluIQCrk47xfl+xITkR2+emu90P4LOIp/Q6ZjGBCw3VuXlhYKlh/jBQYSDN9I4H8FvcjElnt KRgFQEyvPcKt+qBZbHzk3ZdpixcaAkGytA0UzYhDaHy+OWPXT/Rb50Jxk1azS0zj35yf4/UZV3v eDwNFkfgSppDJ64Hf4ncdiMpzf4+AB99j/QGpVpz/HnaHWFEHFf9oa4KSNal9q7dztD0a3NGmHQ 6E+WlWSUZ/MJc/8n5u9H5SqeBG/hX9azQHpx8NRksxKmkbEqZ82WIncliy774YgXOJ2SeZeXAqU +vmSayQ== X-Received: by 2002:a05:6000:2913:b0:4a8:7115:fa08 with SMTP id ffacd0b85a97d-4abb0f3c202mr87619955f8f.13.1796295894287; Thu, 03 Dec 2026 03:04:54 -0800 (PST) Received: from ?IPV6:2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f? ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ad6403fdbbsm70476447f8f.15.2026.12.03.03.04.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 03:04:53 -0800 (PST) Message-ID: <0db82cc0-9048-4970-b780-73156710ee5a@gmail.com> Date: Thu, 3 Dec 2026 11:04:51 +0000 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: phillip.wood@dunelm.org.uk Subject: Re: [PATCH v2] Makefile: let ccache cache objects built with the precompiled header To: Harald Nordgren via GitGitGadget , git@vger.kernel.org Cc: Ben Knoble , Patrick Steinhardt , Harald Nordgren References: Content-Language: en-US From: Phillip Wood In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Harald On 29/10/2026 08:33, Harald Nordgren via GitGitGadget wrote: > From: Harald Nordgren > > 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. > 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 > Signed-off-by: Harald Nordgren > --- > 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 > > ## 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