Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow forge build compilation times #8689

Closed
2 tasks done
alex-roytikh-pop opened this issue Aug 17, 2024 · 5 comments
Closed
2 tasks done

Slow forge build compilation times #8689

alex-roytikh-pop opened this issue Aug 17, 2024 · 5 comments
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled

Comments

@alex-roytikh-pop
Copy link

alex-roytikh-pop commented Aug 17, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (f8aa4af 2024-08-17T00:18:27.502409000Z)

What command(s) is the bug in?

forge build --force

Operating System

macOS (Apple Silicon)

Describe the bug

My team is experiencing very long forge build times, hurting Dev UX. I have spent a good amount of time reading through previous issues related to slow compilation times, but cannot find anything that would be relevant today. Currently running Apple Silicon with Sonoma 14.5.

Project Bytesize

du -sh out
936M    out

I am unable to reproduce the issue with https://github.com/Vectorized/solady. It takes only 15.47s to compile 152 files. https://github.com/latticexyz/mud takes only 1.46s to compile 91 files.

Previous issues I am referencing:
foundry-rs/forge-std#217
foundry-rs/forge-std#225
ethereum/solidity#15141

Things I have tried

  1. forge clean & forge build --force
  2. Enabling and disabling via_ir.
  3. Solc versions
  4. increasing threads to numbers greater than 0. Only 1 thread appears to be used by solc process in htop regardless of setting.

Foundry Configuration

[profile.default]
src = "contracts"
out = "out"
allow_paths = ["../../node_modules"]
libs = ["node_modules","lib"]
test = "test/foundry"
cache_path = "forge-cache"
solc_version = "0.8.26"
evm_version = "cancun"

Build Times

Solc 0.8.13

time forge build --force

[⠒] Compiling...
[⠰] Compiling 556 files with Solc 0.8.13
[⠑] Solc 0.8.13 finished in 262.17s
Compiler run successful

forge build --force  255.94s user 6.55s system 99% cpu 4:23.92 total

Solc 0.8.26
30s quicker than solc 0.8.13

time forge build --force
[⠒] Compiling...
[⠘] Compiling 556 files with Solc 0.8.26
[⠢] Solc 0.8.26 finished in 230.09s
Compiler run successful

forge build --force  225.24s user 5.83s system 99% cpu 3:52.93 total

Solc 0.8.26 via_ir enabled
This runs into the stack too deep issue.

time forge build --force
[⠒] Compiling...
[⠢] Compiling 556 files with Solc 0.8.26
[⠰] Solc 0.8.26 finished in 185.66s
Error: 
Compiler run failed:
Error: Yul exception:Variable value4 is 1 too deep in the stack [ JUNK value4 var_lootSet_mpos _60 _62 var_idx_5 value3 var_total value5 _70 dataSlot_5 value6 value1_3 value2_2 _59 _71 var_setIdx_1 slot_2 ]
memoryguard was present.
YulException: Variable value4 is 1 too deep in the stack [ JUNK value4 var_lootSet_mpos _60 _62 var_idx_5 value3 var_total value5 _70 dataSlot_5 value6 value1_3 value2_2 _59 _71 var_setIdx_1 slot_2 ]
memoryguard was present.

forge build --force  184.66s user 1.06s system 99% cpu 3:06.10 total

Help here would be appreciated! People that have experienced, or investigated the issue previously:

@zerosnacks @mattsse @ZeroEkkusu @marktoda @mds1

@alex-roytikh-pop alex-roytikh-pop added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Aug 17, 2024
@alex-roytikh-pop
Copy link
Author

We have a lot of inline assembly in our contracts, is it possible that there is non-memory-safe assembly causing some sort of compiler issue?

Is there a good way to analyze this?

@aodhgan
Copy link

aodhgan commented Aug 19, 2024

increasing threads to numbers greater than 0. Only 1 thread appears to be used by solc process in htop regardless of setting.

i believe this config var is only relevant for fuzzing, (unfortunately) not compiling

@zerosnacks
Copy link
Member

Unrelated to Foundry, forge build simply wraps the solc compiler. Slow compilation times are almost entirely due to solc. To speed up compilation time try to reduce the amount of dependencies you are pulling in and make sure you enable caching to speed up incremental builds.

@zerosnacks zerosnacks closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2024
@vseae
Copy link

vseae commented Aug 22, 2024

My computer is m3 24gb system version Sonoma 14.6.1

The test script tests a token, inherits the Test contract of forge, and the configuration is enabled via_ir = true, compiler version 0.8.26

When I enable via_ir, it takes me at least a minute to compile a file.

This problem seems to only occur in the inheritance of the forge test contract and the latest macos system.

@ZeroEkkusu
Copy link
Contributor

ZeroEkkusu commented Aug 22, 2024

@vseae Do you mean that a some change in Forge Std has impacted the compilation time via-ir - what happens if you downgrade forge-std with forge install foundry-rs/forge-std@ and then an old version tag from here?

@alex-roytikh-pop

I am unable to reproduce the issue with https://github.com/Vectorized/solady.

Solady uses custom files for Forge Std, can you try using them to see if there's difference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled
Projects
None yet
Development

No branches or pull requests

5 participants