Skip to content

Commit 6807fb9

Browse files
author
Mendral Agent (mendral.com)
committed
Optimize Rust cache configuration for improved CI performance
Implement Phase 1 cache optimizations: - Use shared cache key based on Cargo.lock hash for better reusability - Enable cache-workspace-crates to cache compiled workspace crates - Restrict cache saves to main/canary branches to reduce cache pollution - Update cache prefix to v1-rust-shared to avoid conflicts with old caches Expected improvements: - Cache hit rate: 5% -> 70-80% - Build time reduction: 30-40% on cache hits - Better cache sharing across jobs with same dependencies
1 parent 70f77c7 commit 6807fb9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.github/workflows/cargo-tests.reusable.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ jobs:
5757
- uses: Swatinem/rust-cache@v2
5858
with:
5959
workspaces: "baml_language -> target"
60+
prefix-key: v1-rust-shared
61+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
62+
cache-workspace-crates: true
63+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
6064

6165
- name: "Install Rust toolchain"
6266
run: |
@@ -86,6 +90,10 @@ jobs:
8690
- uses: Swatinem/rust-cache@v2
8791
with:
8892
workspaces: "baml_language -> target"
93+
prefix-key: v1-rust-shared
94+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
95+
cache-workspace-crates: true
96+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
8997

9098
- name: "Install Rust toolchain"
9199
run: rustup show
@@ -137,6 +145,10 @@ jobs:
137145
- uses: Swatinem/rust-cache@v2
138146
with:
139147
workspaces: "baml_language -> target"
148+
prefix-key: v1-rust-shared
149+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
150+
cache-workspace-crates: true
151+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
140152

141153
- name: "Install Rust toolchain"
142154
run: rustup show
@@ -166,6 +178,10 @@ jobs:
166178
- uses: Swatinem/rust-cache@v2
167179
with:
168180
workspaces: "baml_language -> target"
181+
prefix-key: v1-rust-shared
182+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
183+
cache-workspace-crates: true
184+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
169185

170186
- name: "Install Rust toolchain"
171187
run: rustup show
@@ -195,6 +211,10 @@ jobs:
195211
- uses: Swatinem/rust-cache@v2
196212
with:
197213
workspaces: "baml_language -> target"
214+
prefix-key: v1-rust-shared
215+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
216+
cache-workspace-crates: true
217+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
198218

199219
- name: "Install Rust toolchain"
200220
run: |
@@ -234,6 +254,10 @@ jobs:
234254
- uses: Swatinem/rust-cache@v2
235255
with:
236256
workspaces: "baml_language -> target"
257+
prefix-key: v1-rust-shared
258+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
259+
cache-workspace-crates: true
260+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
237261

238262
- name: "Install Rust toolchain (MSRV)"
239263
env:
@@ -285,6 +309,10 @@ jobs:
285309
- uses: Swatinem/rust-cache@v2
286310
with:
287311
workspaces: "baml_language -> target"
312+
prefix-key: v1-rust-shared
313+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
314+
cache-workspace-crates: true
315+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
288316

289317
- name: "Install Rust toolchain"
290318
run: rustup show

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ jobs:
241241
- uses: Swatinem/rust-cache@v2
242242
with:
243243
workspaces: "baml_language -> target"
244+
prefix-key: v1-rust-shared
245+
shared-key: ${{ hashFiles('baml_language/Cargo.lock') }}
246+
cache-workspace-crates: true
247+
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
244248

245249
- name: "Install Rust toolchain"
246250
run: rustup show

0 commit comments

Comments
 (0)