From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796373907; b=lbeULDlTC6suxZCLpXSxpXGW6U2fIBTF5rYhC1TgUrullr1FrqlbNS1L0qqrXfkWC/Vv rDd4xA/bZy31WB9NLLBUSFsxuwAMDEV1lwD3Z/a/x0Nbeyw+d9Nvv45c3EBBCg5S0DbLY PzyMWRtP4dfqE8nzPKAlPJt3n6eSOZ6wO+uQ78UcH/n7u/qFksT/6UuQ007yJBK2ADOrV P/1cGAJINlu+sCf3JEqEiaMn6yhRrZUSlvM5kYegMsUCiIGut9QuTcbHR9hKrH9Sv5dTT +CW2g7Qin8lUsjwpCi6sC9N0oQjpZeJobdrsYa/nBd1ebLPt3QwqzW4B02218pxod9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796373907; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=G6LzDl5HORM1Y3TxaXVK8reGY8ob5RkBOCRBJZy8XFM=; b=LB4OIJ89j70c7RMNiJZH0VB9NJXvyPq8/XAtG2+E71eBJV0b7r3aP6EPmKA0f2gKkrnr zBvx2DkVkCqCBXSc6DWqE1NJVVlBtNWZPpNZChHUmKy86I2YLoiNnQTGX5GgIcNoB8Lb6 dmZwwZ0r7BKOsqSQCv9ddG4qdrapd4g4wDMjT0Kyb/ZKcKcrJNoFXbHVrrlm3xxi2WpNS i9/UpY5H9cUL9dSTKJaAh054W9eVjt75tYLzg8lLbVcDyy4X24A8bWLVbu/mxlBpGySTi px0bZEZvIttHarI8T5a+IZhQtOO8jiG9cUyHMt7vnhpIWW83NVP2kLq8GsJQi0s6Ojw== 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=imy4ZqJM; arc=none smtp.remote-ip=209.85.216.50 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 7284D606A680 for ; Fri, 4 Dec 2026 08:45:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7284D606A680 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=imy4ZqJM Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-3b4021b572dso303793a91.2 for ; Fri, 04 Dec 2026 00:45:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796373906; x=1796978706; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=G6LzDl5HORM1Y3TxaXVK8reGY8ob5RkBOCRBJZy8XFM=; b=imy4ZqJMkvh3frvRSyTBHJRaL68Z8jt0JtjXHp8kw8buOGKfqhjiZRs9Frq+/PDiYw 6oG+cFVtaTIKlFrfSSCOEaDghuG/8S/zN8kXyhdFyItI6700U4DZL7g0JwqtlZ9CbHAe CTTzQ0p3wKL3hMbYEA/3QT5o2PQkGTVCsq3ez7J9ABZLN6wQEcGCgwsSMqzKGKhU1hOG Vx0lNBaDK6Ol/JaBq6j3W/3mMuqrvZmGCkVhuwhH2qlTJnahcDAzNYLW8B5kOy53m/bM mokudc6vroh/0B8t1iZJwxUX9WoT8AidfYc4ABUopX2l++898jJ+qn+varh4GfKq9m6p Z8Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796373906; x=1796978706; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=G6LzDl5HORM1Y3TxaXVK8reGY8ob5RkBOCRBJZy8XFM=; b=gcizGBUAo8Ax2rA1eWKfKKKaVFN5hQMFfNjKRbIrXWQmsIbzd3u9xSI451KMFSTg1e lS4+oTTysbIPwBSl2kjizvFDnFlEmT32ivWP0hLlWFRxKLOL0G9xZA3CTkms5oGutF+t hOQ5V2U+PuIXWRnGha93d2UcSS9rTZGjLpB0bDrZ7O+X5mKJMlUciW3PpLFHR5d9sSbu ptvClL2V+vzBYI3+eUx5TXJPbysH/1UN41YXzIyUjkgzBjOuvJX44T2jB11qvtoSPXKp S67RXJBG8I9q8hWxjUDmwgd6gIdfr2PKzU8Hw/BY54m7jO9+nT7B/pPO7PpldJa9mSC2 eS5A== X-Gm-Message-State: APuU4Z83mm7vijcscWB9mV0OjL6rEUkBFrFegyMn+3ycVUZKy4W5k7My BDyLd2EKCpEph7WInR36NI6Fdb/8tHbKKUhP+mJQxFkBnCgsCy56TMBgbcB3RQ== X-Gm-Gg: AZFdTZf51MG6ZrT6GAqwbgsZtRTwgS6TUIddtD6LhaQfMvIAZfqNS7xIupDtnxykeB9 9ST751zXqpvzWlOeFpmi/3/aXlaK3yTse4A2WII8e3dH8RZL2BOXCdpmKpUjjvqdtB4ebvbhu1l EXMkRjayn69yvbB6WEgRF+kez1Zc9UOnWXGXwFt2Hkb+DOxtCJ54gp8rGlSPEP7W/UG4CUDE1Zd 1JGp2xCIHfyaLiwMGJOUxLYY+W/V4QuPrUJUyVMiNRse62E4wG9f95GkUNpXufbR05AL0ROL/qZ Ylfbcvaw7IfoXX+5vZUQFMmi0SbW1b9pcpCnAPzURl5NcU5EJACIOPxwXrcvubFe3vc07w6TnIG gLk0TfwGocva6Yri0nys6U20c2+GhKm5zElSBnQJcZxPxAyHYfXo/PvNes+92jYO/OVKSPQKEBl rXC2buAnaPShxhHRzYRPLXaXCqF7NjRctlspaXD76NMo2ONg8udD7btgrN/ULlrMAeM5rGXxJMW kGugvENi4GKs6+N1w5Tca/bUYo+KYyNbnuMndiGuBDcPPTODbtqcCUPUXLkYWBF15yBLU6rO/IL ma0Ne7oXro5kXzbyVRFORUeHQmyiQJk= X-Received: by 2002:a17:90b:3e4c:b0:3b0:a38a:6715 with SMTP id 98e67ed59e1d1-3b5e069b209mr1150174a91.59.1796373905615; Fri, 04 Dec 2026 00:45:05 -0800 (PST) Received: from [127.0.0.1] ([4.242.29.129]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7d47c4fsm8618468a91.8.2026.12.04.00.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 00:45:05 -0800 (PST) Message-Id: In-Reply-To: References: From: "Harald Nordgren via GitGitGadget" Date: Fri, 04 Dec 2026 08:45:04 +0000 Subject: [PATCH v3] Makefile: let ccache cache objects built with the precompiled header Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 To: git@vger.kernel.org Cc: Ben Knoble , Patrick Steinhardt , Phillip Wood , Harald Nordgren , Harald Nordgren 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. 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. Clang also records the modification times of the headers in the precompiled header. After switching to a branch that changes one of them and back again, ccache then misses for the precompiled header and for every object built with it. Build the precompiled header with "-fno-pch-timestamp" when the compiler accepts it. Clang uses the modification times to reject a precompiled header that is out of date, and make rebuilds it in that case anyway. On my machine, "make -j8" after such a round trip goes from about 140 seconds to under 20. 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 v3: * Build the precompiled header with -fno-pch-timestamp when the compiler accepts it, so Clang builds also hit the cache after switching branches and back. 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-v3 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2464/HaraldNordgren/makefile-ccache-pch-v3 Pull-Request: https://github.com/git/git/pull/2464 Range-diff vs v2: 1: e61cca8cca ! 1: 2190ea49ec Makefile: let ccache cache objects built with the precompiled header @@ Commit message On my machine, "make clean && make -j8" with a warm cache goes from about 100 seconds to under 30. - 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. + Clang also records the modification times of the headers in the + precompiled header. After switching to a branch that changes one of + them and back again, ccache then misses for the precompiled header and + for every object built with it. Build the precompiled header with + "-fno-pch-timestamp" when the compiler accepts it. Clang uses the + modification times to reject a precompiled header that is out of date, + and make rebuilds it in that case anyway. On my machine, "make -j8" + after such a round trip goes from about 140 seconds to under 20. Signed-off-by: Harald Nordgren @@ Makefile: 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 ++no_pch_timestamp_check = $(shell $(CC) -Xclang -fno-pch-timestamp \ ++ -c -x c /dev/null -o /dev/null 2>&1; \ ++ echo $$?) ++ifeq ($(no_pch_timestamp_check),0) ++PRECOMPILED_HEADER_CFLAGS = -Xclang -fno-pch-timestamp ++endif endif dep_files := $(foreach f,$(OBJECTS) $(PRECOMPILED_HEADER_GCH),$(dir $f).depend/$(notdir $f).d) +@@ Makefile: compdb_args = + endif + + $(PRECOMPILED_HEADER_GCH): %.gch: % GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir) +- $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $< ++ $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(PRECOMPILED_HEADER_CFLAGS) $< + + $(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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a96be506b5..96ddecaaaa 100644 --- a/Makefile +++ b/Makefile @@ -2903,6 +2903,13 @@ 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 +no_pch_timestamp_check = $(shell $(CC) -Xclang -fno-pch-timestamp \ + -c -x c /dev/null -o /dev/null 2>&1; \ + echo $$?) +ifeq ($(no_pch_timestamp_check),0) +PRECOMPILED_HEADER_CFLAGS = -Xclang -fno-pch-timestamp +endif endif dep_files := $(foreach f,$(OBJECTS) $(PRECOMPILED_HEADER_GCH),$(dir $f).depend/$(notdir $f).d) @@ -2941,7 +2948,7 @@ compdb_args = endif $(PRECOMPILED_HEADER_GCH): %.gch: % GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir) - $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $< + $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(PRECOMPILED_HEADER_CFLAGS) $< $(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) $< base-commit: 37b3475fb530c14109211faca33716a173db61ed -- gitgitgadget