Skip to content

Commit a6afe74

Browse files
bowenli86ypatil12
authored andcommitted
perf: add cache for forge build (#1125)
**Motivation:** after multiple round of optimization, the bottleneck in CI is forge build now, which takes 1.2-1.5min this PR added caching for forge build, so that every CI run can restore latest cache, and only compile solidity files that hv been changed, which significantly lowers compile time from 1.2-1.5min t0 <1s **Modifications:** this PR added caching for forge build, so that every CI run can restore latest cache, and only compile solidity files that hv been changed **Result:** significantly lowers compile time from 1.2-1.5min to <1s before adding cache: ![image](https://github.com/user-attachments/assets/09b84912-6a22-449d-b065-8fb67ea6b835) after adding cache: ![image](https://github.com/user-attachments/assets/fb7c20a8-a370-4297-a1bb-82fef99aa4e9)
1 parent 7f32c50 commit a6afe74

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

.github/workflows/foundry.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ jobs:
4747
with:
4848
submodules: recursive
4949

50+
# Restore Forge cache
51+
- name: Cache Forge Build
52+
uses: actions/cache@v3
53+
with:
54+
path: |
55+
cache/
56+
out/
57+
key: ${{ runner.os }}-forge-${{ hashFiles('**/foundry.toml', '**/remappings.txt', 'src/**/*.sol', 'lib/**/*.sol') }}
58+
restore-keys: |
59+
${{ runner.os }}-forge-
60+
5061
# Install the Foundry toolchain.
5162
- name: Install Foundry
5263
uses: foundry-rs/foundry-toolchain@v1
@@ -93,6 +104,17 @@ jobs:
93104
with:
94105
submodules: recursive
95106

107+
# Restore Forge cache
108+
- name: Cache Forge Build
109+
uses: actions/cache@v3
110+
with:
111+
path: |
112+
cache/
113+
out/
114+
key: ${{ runner.os }}-forge-${{ hashFiles('**/foundry.toml', '**/remappings.txt', 'src/**/*.sol', 'lib/**/*.sol') }}
115+
restore-keys: |
116+
${{ runner.os }}-forge-
117+
96118
# Install the Foundry toolchain.
97119
- name: "Install Foundry"
98120
uses: foundry-rs/foundry-toolchain@v1
@@ -126,6 +148,17 @@ jobs:
126148
with:
127149
submodules: recursive
128150

151+
# Restore Forge cache
152+
- name: Cache Forge Build
153+
uses: actions/cache@v3
154+
with:
155+
path: |
156+
cache/
157+
out/
158+
key: ${{ runner.os }}-forge-${{ hashFiles('**/foundry.toml', '**/remappings.txt', 'src/**/*.sol', 'lib/**/*.sol') }}
159+
restore-keys: |
160+
${{ runner.os }}-forge-
161+
129162
# Install the Foundry toolchain.
130163
- name: "Install Foundry"
131164
uses: foundry-rs/foundry-toolchain@v1
@@ -160,20 +193,20 @@ jobs:
160193
- uses: actions/checkout@v4
161194
with:
162195
submodules: recursive
163-
164-
# Cache Foundry dependencies
165-
- name: Cache Foundry dependencies
196+
197+
# Restore Foundry and Forge cache
198+
- name: Cache Foundry Dependencies
166199
uses: actions/cache@v3
167200
with:
168201
path: |
169202
~/.cargo
170203
~/.foundry
171204
out/
172205
cache/
173-
key: ${{ runner.os }}-foundry-${{ hashFiles('**/foundry.toml', '**/Cargo.lock') }}
206+
key: ${{ runner.os }}-forge-${{ hashFiles('**/foundry.toml', '**/remappings.txt', 'src/**/*.sol', 'lib/**/*.sol', '**/Cargo.lock') }}
174207
restore-keys: |
175208
${{ runner.os }}-foundry-
176-
209+
177210
# Install the Foundry toolchain.
178211
- name: "Install Foundry"
179212
uses: foundry-rs/foundry-toolchain@v1

0 commit comments

Comments
 (0)