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

workspace inheritiance slowing down cargo startup times #10747

Closed
Muscraft opened this issue Jun 10, 2022 · 0 comments · Fixed by #10776
Closed

workspace inheritiance slowing down cargo startup times #10747

Muscraft opened this issue Jun 10, 2022 · 0 comments · Fixed by #10776
Labels
A-workspace-inheritance Area: workspace inheritance RFC 2906 C-bug Category: bug Performance Gotta go fast!

Comments

@Muscraft
Copy link
Member

Muscraft commented Jun 10, 2022

Problem

@ehuss noticed that workspace inheritance caused a significant increase in startup times when using workspace inheritance.

When running the same test (as described here) I got

Benchmark 1: cd rust; cargo +nightly metadata
  Time (mean ± σ):     156.7 ms ±   2.3 ms    [User: 110.0 ms, System: 35.3 ms]
  Range (min … max):   152.5 ms … 161.0 ms    18 runs
 
Benchmark 2: cd rust2; cargo +nightly metadata
  Time (mean ± σ):     199.9 ms ±   1.2 ms    [User: 150.0 ms, System: 38.8 ms]
  Range (min … max):   196.8 ms … 202.5 ms    14 runs
 
Summary
  'cd rust; cargo +nightly metadata' ran
    1.28 ± 0.02 times faster than 'cd rust2; cargo +nightly metadata'

This is a large increase in time and should be addressed before stabilization

Steps

Original steps

@ehuss's testing notes

Modified steps using +nightly

  1. Extract this file in benches/workspaces
    rust2.zip

    This is just a quick hack that adds inheritance to a bunch of packages, but I didn't really put much thought into setting it up.

  2. Extract rust.tgz in that directory, too.

  3. Prime the target directory with a cache of rustc info. In rust and rust2, run: cargo +nightly c -p linkchecker. Otherwise it would be measuring rustc overhead.

  4. Test out some command that spends most of its time loading the workspace. There aren't very many good candidates, but cargo metadata or cargo tree can work. I use hyperfine for quick measurements. For example:

hyperfine "cd rust; cargo +nightly metadata" "cd rust2; cargo +nightly metadata"

Possible Solution(s)

One possible solution would be to record paths of workspace roots that can be checked before walking the filesystem to look for a workspace root. The biggest problem with this is where to record everything. Config is one place and there is some precedence for a cache being put in there.

Notes

No response

Version

cargo 1.63.0-nightly (4d92f07f3 2022-06-09)
release: 1.63.0-nightly
commit-hash: 4d92f07f34ba7fb7d7f207564942508f46c225d3
commit-date: 2022-06-09
host: aarch64-apple-darwin
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.79.1 (sys:0.4.55+curl-7.83.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 12.4.0 [64-bit]
@Muscraft Muscraft added the C-bug Category: bug label Jun 10, 2022
@weihanglo weihanglo added A-workspace-inheritance Area: workspace inheritance RFC 2906 Performance Gotta go fast! labels Jun 11, 2022
bors added a commit that referenced this issue Jun 18, 2022
Add a benchmark for workspace initialization

It [was suggested](#10736 (comment)) that a benchmark for workspace initialization should be added. This was suggested because there were issues with the performance of [workspace inheritance](#10747) 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
@bors bors closed this as completed in ca190ac Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-workspace-inheritance Area: workspace inheritance RFC 2906 C-bug Category: bug Performance Gotta go fast!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants