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

chore: optimize out retriggering 2nd stage of build + wasmopt stage #292

Merged
merged 11 commits into from
Jan 22, 2025

Conversation

dj8yfo
Copy link
Collaborator

@dj8yfo dj8yfo commented Jan 16, 2025

reason for this pr is that LazyLock initialization block
doesn't work to ensure tested contracts are built only once for cargo nextest run as cargo-nextest uses a process-per-test runner,
and for usual cargo test workflows it may not be convenient/possible to unite all tests into a single test module, thus contracts' build will run at least once per each test module.

This pr minimizes time spent on contracts' rebuilding after initial build, so that LazyLock init block isn't that much needed any more, but it depends on separating target folders of different contracts being tested similar to dj8yfo/neardevhub-contract@cbbf0ee to avoid partially rebuilding contracts starting with near-sdk-macros crate, if it's shared in common release profile when different contracts are in a workspace.


this results in

• Building contract
 │     Finished `release` profile [optimized] target(s) in 0.08s

• Running an optimize for size post-step with wasm-opt...
/home/user/Documents/code/near/neardevhub-contract/target/wasm32-unknown-unknown/release/devhub.wasm -> /tmp/optimized-s2bmSK.wasm
• done

✓ Contract successfully built! (in CARGO_NEAR_BUILD_ENVIRONMENT=host)
     -                Binary: /home/user/Documents/code/near/neardevhub-contract/target/near/devhub.wasm
     - SHA-256 checksum hex : 1f568ea4c5eabf9c947a201f3adf38a4e47056658aa512fdfc722f17de9d3aa3
     - SHA-256 checksum bs58: 37LC32jmZFmZN8KesPipwUn4ZyhW4994coXqSWMdnDQv
     -                   ABI: /home/user/Documents/code/near/neardevhub-contract/target/near/devhub_abi.json
     -          Embedded ABI: /home/user/Documents/code/near/neardevhub-contract/target/near/devhub_abi.zst
    Finished cargo near build in 5s
Here is the console command if you ever need to re-run it again:
cargo near build non-reproducible-wasm

instead of

• Building contract
 │    Compiling near-sdk-macros v5.5.0
 │    Compiling near-sdk v5.5.0
 │    Compiling devhub_common v0.1.0 (/home/user/Documents/code/near/neardevhub-contract/d
evhub_common)
 │    Compiling near-contract-standards v5.5.0
 │    Compiling devhub v0.2.0 (/home/user/Documents/code/near/neardevhub-contract)
 │     Finished `release` profile [optimized] target(s) in 15.52s

• Running an optimize for size post-step with wasm-opt...
/home/user/Documents/code/near/neardevhub-contract/target/wasm32-unknown-unknown/release/d
evhub.wasm -> /tmp/optimized-FbzCfP.wasm
• done

✓ Contract successfully built! (in CARGO_NEAR_BUILD_ENVIRONMENT=host)
     -                Binary: /home/user/Documents/code/near/neardevhub-contract/target/ne
ar/devhub.wasm
     - SHA-256 checksum hex : 1f568ea4c5eabf9c947a201f3adf38a4e47056658aa512fdfc722f17de9d3aa3
     - SHA-256 checksum bs58: 37LC32jmZFmZN8KesPipwUn4ZyhW4994coXqSWMdnDQv
     -                   ABI: /home/user/Documents/code/near/neardevhub-contract/target/ne
ar/devhub_abi.json
     -          Embedded ABI: /home/user/Documents/code/near/neardevhub-contract/target/ne
ar/devhub_abi.zst
    Finished cargo near build in 20s

on rebuilds.

and wasm-opt stage skipping was handled in e746699 . No file locks were added, it would still waste some cpu, if multiple builders enter the wasm-opt stage around the same time, but it does save on time and locks are perceived as unneeded complexity at this time.


vaguely related to Near-One/omni-bridge#184

@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jan 17, 2025

adding dj8yfo/neardevhub-contract@cbbf0ee
prevents partial rebuilds of neardevhub-contract and neardevhub-community-factory on

 │        Dirty near-sdk-macros v5.7.0: the environment variable CARGO_NEAR_ABI_PATH changed
 │    Compiling near-sdk-macros v5.7.0

due to near-sdk-macros crate's builds being shared in the same release profile.

Only wasm-opt computing overhead is left per each test with cargo nextest run (5 s for neardevhub and 1 s for community-factory)
Summary [ 204.822s] ?? -> Summary [ 49.310s]


if the abi logic isn't being used/tested in tests, both the reasons of rebuilds can also be eliminated by doing .no_abi(true) build

dj8yf0μl added 2 commits January 20, 2025 18:06
This reverts commit 9d30422.
This reverts commit e91bd03.
@dj8yfo dj8yfo force-pushed the shorten_2nd_phase_of_build_on_rebuild_to_fast branch from 8ab53be to 5b68575 Compare January 20, 2025 16:06
dj8yf0μl and others added 2 commits January 20, 2025 19:08
… is newer than the original wasm, which means that we have already optimized it
@dj8yfo dj8yfo force-pushed the shorten_2nd_phase_of_build_on_rebuild_to_fast branch from 5b68575 to e746699 Compare January 20, 2025 17:09
@dj8yfo dj8yfo changed the title chore: optimize out retriggering 2nd stage of build chore: optimize out retriggering 2nd stage of build + wasmopt stage Jan 20, 2025
@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jan 20, 2025

the result of adding e746699 is measurable (numbers are from second test run to account just for rebuilds, the initial contracts build time is significantly more than the times of tests per se)

update rev (normal verbosity, wasm-opt duration, wasm-opt not skipped on rerun)
dj8yfo/neardevhub-contract@c34fff3

  • cargo test
    • 56.72 s
    • 54.13 s
    • 54.34 s
  • cargo nextest run
    • 42.6 s
    • 42.6 s
    • 43.7 s

update rev of cargo-near-build patch (wasm-opt stage skipped)
dj8yfo/neardevhub-contract@3e03d0e

  • cargo test
    • 33 s
    • 32.43 s
    • 31.87 s
  • cargo nextest run
    • 32.25 s
    • 32.35 s
    • 32.31 s

@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jan 20, 2025

running cargo test on clean state (taking into account inital contracts' build) takes 542 s,
and cargo nextest run - 472 s

cargo nextest run from scratch on the same code with unpatched version (from crates.io and not
from this pr) dj8yfo/neardevhub-contract@dd3ada1
of cargo-near-build - 527 s, so the time cut of this pr is 55 s for 7 tests which build contracts.
And 72 s unpatched vs 32 s patched for second run for 7 tests.

@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jan 21, 2025

@race-of-sloths include

@race-of-sloths
Copy link

race-of-sloths commented Jan 21, 2025

@dj8yfo Thank you for your contribution! Your pull request is now a part of the Race of Sloths!
Congratulatory messages are spent out! Your results have exceeded our imagination!

Shows inviting banner with latest news.

Shows profile picture for the author of the PR

Current status: waiting for finalization

The pull request is merged, you have 24 hours to finalize your scoring. The scoring ends Thu Jan 23 12:48:20 2025

Reviewer Score
@akorchyn 13

Your contribution is much appreciated with a final score of 13!
You have received 130 Sloth points for this contribution

@akorchyn received 25 Sloth Points for reviewing and scoring this pull request.

What is the Race of Sloths

Race of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow

For contributors:

  • Tag @race-of-sloths inside your pull requests
  • Wait for the maintainer to review and score your pull request
  • Check out your position in the Leaderboard
  • Keep weekly and monthly streaks to reach higher positions
  • Boast your contributions with a dynamic picture of your Profile

For maintainers:

  • Score pull requests that participate in the Race of Sloths and receive a reward
  • Engage contributors with fair scoring and fast responses so they keep their streaks
  • Promote the Race to the point where the Race starts promoting you
  • Grow the community of your contributors

Feel free to check our website for additional details!

Bot commands
  • For contributors
    • Include a PR: @race-of-sloths include to enter the Race with your PR
  • For maintainers:
    • Invite contributor @race-of-sloths invite to invite the contributor to participate in a race or include it, if it's already a runner.
    • Assign points: @race-of-sloths score [1/2/3/5/8/13] to award points based on your assessment.
    • Reject this PR: @race-of-sloths exclude to send this PR back to the drawing board.
    • Exclude repo: @race-of-sloths pause to stop bot activity in this repo until @race-of-sloths unpause command is called

akorchyn
akorchyn previously approved these changes Jan 22, 2025
Copy link
Collaborator

@akorchyn akorchyn left a comment

Choose a reason for hiding this comment

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

@race-of-sloths score 13

Two nits that you might skip:)

cargo-near-build/src/near/build/mod.rs Outdated Show resolved Hide resolved
cargo-near-build/src/near/build/mod.rs Outdated Show resolved Hide resolved
@dj8yfo dj8yfo enabled auto-merge (squash) January 22, 2025 12:05
@dj8yfo dj8yfo disabled auto-merge January 22, 2025 12:34
@dj8yfo dj8yfo merged commit 2851dc6 into near:main Jan 22, 2025
17 checks passed
@frol frol mentioned this pull request Jan 22, 2025
dj8yfo pushed a commit that referenced this pull request Jan 22, 2025
## 🤖 New release
* `cargo-near`: 0.13.2 -> 0.13.3 (✓ API compatible changes)
* `cargo-near-build`: 0.4.2 -> 0.4.3 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `cargo-near`
<blockquote>

##
[0.13.3](cargo-near-v0.13.2...cargo-near-v0.13.3)
- 2025-01-22

### Other

- update near-cli-rs to 0.18.0 (#293)
- update `cargo near new` template `image` and `image_digest`
([#288](#288))
- update `cargo near new` template `image` and `image_digest`
([#283](#283))
</blockquote>

## `cargo-near-build`
<blockquote>

##
[0.4.3](cargo-near-build-v0.4.2...cargo-near-build-v0.4.3)
- 2025-01-22

### Fixed

- remove from env CARGO_ENCODED_RUSTFLAGS for easier nested builds,
simplify RUSTFLAGS computation rule (#289)

### Other

- optimize out retriggering 2nd stage of build + of wasmopt stage in
tests context (#292)
- update `cargo near new` template `image` and `image_digest`
([#288](#288))
- unpin `cc` after issue resolution (#285)
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
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.

4 participants