From 54338b5a26c7eb8dcd0586bf93d67a1cb5c06803 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Wed, 2 Nov 2022 14:14:38 -0500
Subject: [PATCH 04/11] cirrus/ccache: avoid clearing cache until after all
 compilations

Local storage use is of no concern, but it's bad if we have lower cache
hit ratio due to pruning which occurs during earlier compilations.
---
 .cirrus.yml | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 061c8e1c7df..47c4caf51ac 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -236,7 +236,7 @@ task:
     - name: Linux - Debian Bullseye - Meson
 
       env:
-        CCACHE_MAXSIZE: "400M" # tests two different builds
+        CCACHE_MAXSIZE: "800M" # tests two different builds
 
       configure_script: |
         su postgres <<-EOF
@@ -287,6 +287,10 @@ task:
           PYTHONCOERCECLOCALE=0 LANG=C meson test $MTEST_ARGS -C build-32 --num-processes ${TEST_JOBS}
         EOF
 
+      ccache_stats_end_script:
+        ccache -s
+        CCACHE_MAXSIZE=400M ccache --cleanup
+
       on_failure:
         <<: *on_failure_meson
 
@@ -492,8 +496,10 @@ task:
     BUILD_JOBS: 4
 
     # Use larger ccache cache, as this task compiles with multiple compilers /
-    # flag combinations
-    CCACHE_MAXSIZE: "1GB"
+    # flag combinations.  The cache size is set high now, and manually pruned later,
+    # to avoid cache cleaning cycles during the early compilations pruning
+    # compilation results which could've been used during later compilations.
+    CCACHE_MAXSIZE: "2G"
     CCACHE_DIR: "/tmp/ccache_dir"
 
     LINUX_CONFIGURE_FEATURES: *LINUX_CONFIGURE_FEATURES
@@ -612,6 +618,10 @@ task:
       time make -s cpluspluscheck EXTRAFLAGS='-fmax-errors=10'
 
   always:
+    ccache_stats_end_script:
+      ccache -s
+      CCACHE_MAXSIZE=1G ccache --cleanup
+
     upload_caches: ccache
 
 
-- 
2.25.1

