FuelLabs / sway

🌴 Empowering everyone to build reliable and efficient smart contracts.
https://docs.fuel.network/docs/sway/
Apache License 2.0
62.96k stars 5.33k forks source link

Latest version of the toolchain causes forc build process to get killed #6219

Closed Mantas-M closed 15 hours ago

Mantas-M commented 6 days ago

Related Component

compiler

Problem

Using the previous toolchain, all the projects in my workspace compiled as usual. Currently, during the forc build process, it gets stuck and after a while gets killed

[1]    64024 killed     forc build

Some smaller contracts compile but a large amount of them do not.

Steps

  1. Run forc build either in the root of the workspace or in the forc project dir
  2. Wait until it gets stuck
  3. [1] 64024 killed forc build

Possible Solution(s)

No response

Notes

Worked previously on forc - Update available : 0.60.0 -> 0.61.2 fuel-core - Update available : 0.26.0 -> 0.28.0 fuel-core-keygen - Update available : 0.26.0 -> 0.28.0 fuelup - Up to date : 0.25.1

Device Macbook M3 Pro macOS 14.5 (23F79)

Installed components

latest-aarch64-apple-darwin
  forc - Up to date : 0.61.2
  fuel-core - Up to date : 0.28.0
  fuel-core-keygen - Up to date : 0.28.0
fuelup - Up to date : 0.25.1
kayagokalp commented 6 days ago

Hey @Mantas-M thanks for the issue. Can you provide a reproducible so that i can debug this. I cannot reproduce this on a fresh project. Also looks like you bumped from 0.60.0 to 0.61.2, it would be really helpful to see if this also happens with 0.61.0, 0.61.1.

IGI-111 commented 2 days ago

I have a minimal repro here: https://github.com/IGI-111/forc-bug-repro It looks to be a forc bug since it happens with basically empty source.

kayagokalp commented 1 day ago

I did some digging. It turns out that this is due to the memory usage of the compiler not about forc-pkg, we have two bumps:

~1.6gb to ~5.5 gb -> https://github.com/FuelLabs/sway/commit/0e567287b4e0abe5394fb5f5f4e9d4a8528a6e13 ~5.5 gb to ~20gb -> https://github.com/FuelLabs/sway/commit/76595ed3f3279a1b495bdee2de38f092a3cdb043

For the following project: https://github.com/IGI-111/forc-bug-repro

I benchmarked between v0.61.2 tag and v0.60.0 tag, with the following command on my mac:

/usr/bin/time -l cargo run --release -p forc -- build --path ../../test_projects/forc-bug-repro

If you are using a linux distro you -l should be -v for the time.

kayagokalp commented 1 day ago

Root cause seems to be https://github.com/FuelLabs/sway/commit/76595ed3f3279a1b495bdee2de38f092a3cdb043 more specifically there is a comment there about possible reason:

Step 1 unfortunately adds an extra cloning step in the namespace module, but I don't think it's avoidable at the moment. To avoid this extra cloning step we would need to have a better way of building the external module structure than we currently have. https://github.com/FuelLabs/sway/issues/5498 tracks this and other issues.

@tritao mentioned ~1.6gb to ~5.5 gb -> https://github.com/FuelLabs/sway/commit/0e567287b4e0abe5394fb5f5f4e9d4a8528a6e13 is fixed by: https://github.com/FuelLabs/sway/commit/2cbc24dc2e4ecab1e2b65fb8542d4650e313db99 and i can confirm that ~20gb mem usage from the repro reduced to ~15gb with that commit. So it looks like the 4gb bump there is removed.

kayagokalp commented 15 hours ago

After #6249, this is resolved. Closing as completed.