Skip to content

Conversation

bowenli86
Copy link
Contributor

@bowenli86 bowenli86 commented Feb 18, 2025

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

after adding cache:
image

@bowenli86 bowenli86 marked this pull request as ready for review February 18, 2025 19:53
@bowenli86 bowenli86 changed the title perf: add cache for forge build feat: add cache for forge build Feb 18, 2025
0xClandestine
0xClandestine previously approved these changes Feb 18, 2025
Copy link
Member

@0xClandestine 0xClandestine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestions, looks good otherwise

path: |
cache/
out/
key: ${{ runner.os }}-forge-${{ hashFiles('**/foundry.toml', '**/remappings.txt', 'src/**/*.sol', 'lib/**/*.sol') }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the commit hash as the key? Since the above defined files may not necessarily change.

Copy link
Contributor Author

@bowenli86 bowenli86 Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't hv strong opinion, any special benefits of using commit hash?

benefits of current way it's more cohesive within iterations of a given PR, which may hv multiple rounds of CI and build can be totally skipped

# Cache Foundry dependencies

# Restore Foundry and Forge cache
- name: Cache Foundry dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize first letters

Suggested change
- name: Cache Foundry dependencies
- name: Cache Foundry Dependencies

@0xClandestine 0xClandestine changed the title feat: add cache for forge build perf: add cache for forge build Feb 18, 2025
@bowenli86
Copy link
Contributor Author

looks like the approval is gone after i fixed typo, @0xClandestine needs another approval pls

@0xClandestine 0xClandestine merged commit c9b1242 into dev Feb 18, 2025
9 checks passed
@0xClandestine 0xClandestine deleted the perf/cache branch February 18, 2025 22:30
ypatil12 pushed a commit that referenced this pull request Feb 22, 2025
**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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants