Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

perf(ci): the compile cache is sized to what it caches, and stops hoarding copies

yhh60a049226bd8
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e7cd1f2a5..0d6c74afb 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -51,11 +51,14 @@ jobs:
with:
version: 5.0.0
+ # 500M could not hold ONE generation of this job's objects: 1157 compile
+ # calls, 76 cleanups inside the single job, 11% hits. Sized to the measurement.
+ # Every workflow sharing this key must agree, or the smallest one trims it back.
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ runner.os }}-emscripten
- max-size: 500M
+ max-size: 2G
- name: Build Web target
run: node build-tools/cli.js build -t web --no-sync
@@ -126,10 +129,14 @@ jobs:
with:
version: 5.0.0
+ # No size here meant the action's 500M default, and Debug+ASan objects run
+ # about 2.6 MB each — 193 of them filled it to 100% with 53 cleanups. One
+ # generation is ~500 MB, so this holds two; the budget is shared, not free.
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: emscripten-asan
+ max-size: 1G
- name: Configure (ASan + UBSan)
run: |
diff --git a/.github/workflows/cache-prune.yml b/.github/workflows/cache-prune.yml
new file mode 100644
index 000000000..c12ddbeab
--- /dev/null
+++ b/.github/workflows/cache-prune.yml
@@ -0,0 +1,74 @@
+name: Prune ccache snapshots
+
+# ccache-action appends a timestamp to its key on every save and never removes
+# the snapshot it replaced. Only the newest per key is ever restored, so the rest
+# are dead weight — and they are not free: 20 copies held 8.9 GB of this repo's
+# 10 GB cache budget, which evicts by LRU. The caches that ARE read every run
+# (native-deps, pnpm) were being pushed out by ccache snapshots nothing reads.
+#
+# This keeps the newest snapshot per ccache key and deletes the rest, which is
+# what makes the 2G ceiling in build.yml affordable rather than ruinous.
+
+on:
+ workflow_run:
+ workflows: [Build]
+ types: [completed]
+ # A safety net: workflow_run cannot fire for a run that never started, and a
+ # week of those would refill the budget on its own.
+ schedule:
+ - cron: '17 5 * * *'
+ workflow_dispatch:
+
+# Deleting a cache is the only thing this needs, and the only thing it can do.
+# build.yml stays at contents:read precisely because this lives apart from it.
+permissions:
+ actions: write
+
+jobs:
+ prune:
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - name: Keep the newest snapshot of each ccache key
+ env:
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ run: |
+ set -euo pipefail
+ # per_page=100 is this endpoint's maximum, and --paginate would apply
+ # --jq once per page, which would break the grouping below. One page is
+ # the whole list at this repo's scale; the daily run covers any overflow.
+ gh api "repos/$REPO/actions/caches?per_page=100" > caches.json
+
+ # A key is <prefix>-<ISO timestamp>. Group on the prefix, keep the
+ # newest by creation, and list every older one.
+ jq -r '
+ [ .actions_caches[] | select(.key | startswith("ccache-")) ]
+ | group_by(.key | sub("-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:.]+Z$"; ""))
+ | .[] | sort_by(.created_at) | reverse | .[0]
+ | "keeping \(.key) (\(.size_in_bytes / 1048576 | floor) MB)"
+ ' caches.json
+
+ jq -r '
+ [ .actions_caches[] | select(.key | startswith("ccache-")) ]
+ | group_by(.key | sub("-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:.]+Z$"; ""))
+ | map(sort_by(.created_at) | reverse | .[1:])
+ | flatten | .[] | "\(.id)\t\(.size_in_bytes)\t\(.key)"
+ ' caches.json > stale.tsv
+
+ freed=0
+ count=0
+ while IFS=$'\t' read -r id size key; do
+ [ -n "$id" ] || continue
+ # A snapshot can go between the listing and here — another prune, or
+ # GitHub's own LRU. That is the outcome this wanted, not an error.
+ if gh api --method DELETE "repos/$REPO/actions/caches/$id" --silent 2>/dev/null; then
+ echo "deleted $key ($((size / 1048576)) MB)"
+ freed=$((freed + size))
+ count=$((count + 1))
+ else
+ echo "already gone: $key"
+ fi
+ done < stale.tsv
+
+ echo "pruned $count snapshot(s), $((freed / 1048576)) MB reclaimed"
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 14ceda27a..c5c77aa53 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -45,11 +45,13 @@ jobs:
with:
version: 5.0.0
+ # Shares the key build.yml fills, so it has to agree on the ceiling —
+ # whichever workflow names the smallest one trims the cache back to it.
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ runner.os }}-emscripten
- max-size: 500M
+ max-size: 2G
- name: Build every target
run: node build-tools/cli.js build -t all --no-sync
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index 820796747..d80b18011 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -95,11 +95,13 @@ jobs:
with:
version: 5.0.0
+ # Shares the key build.yml fills, so it has to agree on the ceiling —
+ # whichever workflow names the smallest one trims the cache back to it.
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ runner.os }}-emscripten
- max-size: 500M
+ max-size: 2G
- name: Build engine and sync to desktop
run: node build-tools/cli.js build -t all