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

Add a benchmark for workspace initialization #10754

Merged
merged 2 commits into from
Jun 18, 2022
Merged

Conversation

Muscraft
Copy link
Member

It was suggested that a benchmark for workspace initialization should be added. This was suggested because there were issues with the performance of workspace inheritance as well as a general way to track the workspace initialization time across cargo changes

Changes

  • Moved common functions out of resolve.rs to a shared lib.rs
  • Added a new struct to be used when creating a new benchmark
    • This was done because env!("CARGO_TARGET_TMPDIR") would fail to compile when put inside of the new lib.rs
  • Added a new workspace test for workspace inheritance
    • This new workspace does not have a repo that it was built from and if one needs to be made I can change that

@rust-highfive
Copy link

r? @ehuss

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2022
@epage
Copy link
Contributor

epage commented Jun 14, 2022

clap 3.2.3 disables the deprecations by default and people can enable them with the deprecated feature.

In theory, this should unblock CI so I re-kicked off the jobs.

benches/benchsuite/src/lib.rs Outdated Show resolved Hide resolved
benches/benchsuite/src/lib.rs Outdated Show resolved Hide resolved
benches/benchsuite/src/lib.rs Outdated Show resolved Hide resolved
benches/benchsuite/src/lib.rs Outdated Show resolved Hide resolved
benches/benchsuite/src/lib.rs Outdated Show resolved Hide resolved
benches/benchsuite/benches/workspace_initialization.rs Outdated Show resolved Hide resolved
@epage
Copy link
Contributor

epage commented Jun 17, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 17, 2022

📌 Commit f182411 has been approved by epage

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2022
@bors
Copy link
Collaborator

bors commented Jun 17, 2022

⌛ Testing commit f182411 with merge 6434777ca73ff8bf68cae42908e27dfcaa8b2ffc...

@bors
Copy link
Collaborator

bors commented Jun 17, 2022

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 17, 2022
@weihanglo
Copy link
Member

@bors retry

Cannot tell why failed.

image

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2022
@bors
Copy link
Collaborator

bors commented Jun 18, 2022

⌛ Testing commit f182411 with merge 17d4db0...

@bors
Copy link
Collaborator

bors commented Jun 18, 2022

☀️ Test successful - checks-actions
Approved by: epage
Pushing 17d4db0 to master...

@bors bors merged commit 17d4db0 into rust-lang:master Jun 18, 2022
bors added a commit that referenced this pull request Jun 20, 2022
remove unused dependency from benchsuite

In #10754 I added a new benchmark to the benchsuite. While figuring out the best way to add the new benchmark, I added `cargo-test-support` as a dependency. It appears I missed removing it before making the PR.

This PR removes `cargo-test-support` since it is not needed
@ehuss ehuss added this to the 1.63.0 milestone Jul 1, 2022
bors added a commit that referenced this pull request Jul 5, 2022
add a cache for discovered workspace roots

## History
`@ehuss` [noticed that](#10736 (comment)) workspace inheritance caused a significant increase in startup times when using workspace inheritance. This brought up the creation of #10747.

When using a similar test setup [to the original](#10736 (comment)) I got
```
Benchmark 1: cd rust; ../../../target/release/cargo metadata
  Time (mean ± σ):     149.4 ms ±   3.8 ms    [User: 105.9 ms, System: 31.7 ms]
  Range (min … max):   144.2 ms … 162.2 ms    19 runs

Benchmark 2: cd rust-ws-inherit; ../../../target/release/cargo metadata
  Time (mean ± σ):     191.6 ms ±   1.4 ms    [User: 145.9 ms, System: 34.2 ms]
  Range (min … max):   188.8 ms … 193.9 ms    15 runs
```

This showed a large increase in time per cargo command when using workspace inheritance.

During the investigation of this issue, other [performance concerns were found and addressed](#10761). This resulted in a drop in time across the board but heavily favored workspace inheritance.
```
Benchmark 1: cd rust; ../../../target/release/cargo metadata
  Time (mean ± σ):     139.3 ms ±   1.7 ms    [User: 99.8 ms, System: 29.4 ms]
  Range (min … max):   137.1 ms … 144.5 ms    20 runs

Benchmark 2: cd rust-ws-inherit; ../../../target/release/cargo metadata
  Time (mean ± σ):     161.7 ms ±   1.4 ms    [User: 120.4 ms, System: 31.2 ms]
  Range (min … max):   158.0 ms … 164.6 ms    18 runs
```

## Performance after changes
`hyperfine --warmup 10 "cd rust; ../../../target/release/cargo metadata" "cd rust-ws-inherit; ../../../target/release/cargo metadata" --runs 40`
```
Benchmark 1: cd rust; ../../../target/release/cargo metadata
  Time (mean ± σ):     140.1 ms ±   1.5 ms    [User: 99.5 ms, System: 30.7 ms]
  Range (min … max):   137.4 ms … 144.0 ms    40 runs

Benchmark 2: cd rust-ws-inherit; ../../../target/release/cargo metadata
  Time (mean ± σ):     141.8 ms ±   1.6 ms    [User: 100.9 ms, System: 30.9 ms]
  Range (min … max):   138.4 ms … 145.4 ms    40 runs
```

[New Benchmark](#10754)
`cargo bench -- workspace_initialization/rust`
```
workspace_initialization/rust
    time:   [14.779 ms 14.880 ms 14.997 ms]
workspace_initialization/rust-ws-inherit
    time:   [16.235 ms 16.293 ms 16.359 ms]
```

## Changes Made
- [Pulled a commit](bbd41a4) from `@ehuss` that deduplicated finding a workspace root to make the changes easier
- Added a cache in `Config` to hold found `WorkspaceRootConfig`s
  - This makes it so manifests should only be parsed once
- Made `WorkspaceRootConfig` get added to the cache when parsing a manifest

## Testing Steps
To check the new benchmark:
1. `cd benches/benchsuite`
2. `cargo bench -- workspace_initialization/rust`

Using `hyperfine`:
1. run `cargo build --release`
2. extract `rust` and `rust-ws-inherit` in `benches/workspaces`
3. cd `benches/workspaces`
4. Prime the target directory with a cache of `rustc` info. In `rust` and `rust-ws-inherit`, run: `cargo +nightly c -p linkchecker`. Otherwise it would be measuring `rustc` overhead.
4. run `hyperfine --warmup 10 "cd rust; ../../../target/release/cargo metadata" "cd rust-ws-inherit; ../../../target/release/cargo metadata" --runs 40`

closes #10747
@Muscraft Muscraft deleted the benchsuite branch August 17, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants