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 progress indicator for cargo clean #10236

Merged
merged 5 commits into from
Apr 10, 2022
Merged

Conversation

theo-lw
Copy link
Contributor

@theo-lw theo-lw commented Dec 28, 2021

Closes #9981.

Cleaning the entire target directory:

Cleaning target

Cleaning some packages:

Cleaning a few packages

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 28, 2021
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

The progress bar seems disappear when --verbose is specified with -p. I guess it is replaced by the output of Removing .... We can tick the progress bar after each rm_rf, but if a removal is stuck the progress bar still disappears for a while.

let pkg_dir = format!("{}-*", pkg.name());
progress.tick_now(pkg_idx + 1, packages.len(), &format!(": {}", pkg.name()))?;
Copy link
Member

Choose a reason for hiding this comment

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

What if there is a package with lots of artifacts? I feel like it would still look like "get stuck"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would. I added a message listing of the # of files/folders cleaned so users can see that it isn't stuck.

Comment on lines 247 to 251
if entry.file_type().is_dir() {
paths::remove_dir(entry.path())?;
} else {
paths::remove_file(entry.path())?;
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure but maybe keep the verbose Removing ... as what fn rm_rf does? Though it only displays Removing /path/to/target-dir

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, updated so the verbose Removing ... is kept.

@@ -231,6 +235,25 @@ fn rm_rf_glob(pattern: &Path, config: &Config) -> CargoResult<()> {
Ok(())
}

fn rm_rf_with_progress(path: &Path, progress: &mut Progress<'_>) -> CargoResult<()> {
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Feel like progress can be a part of function body instead of a parameter.

@theo-lw
Copy link
Contributor Author

theo-lw commented Dec 29, 2021

Fixed the issue of Removing... not being shown in verbose mode:

Image from Gyazo

Fixed the issue of the progress bar disappearing in verbose mode:

Image from Gyazo

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Awesome. I think it's good to move forward and wait the review from maintainers. 🎉

src/cargo/ops/cargo_clean.rs Outdated Show resolved Hide resolved
src/cargo/ops/cargo_clean.rs Outdated Show resolved Hide resolved
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me, thanks for this!

Ok(())
}

fn clean_entire_folder(path: &Path, config: &Config) -> CargoResult<()> {
let num_paths = walkdir::WalkDir::new(path).into_iter().count();
Copy link
Member

Choose a reason for hiding this comment

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

This naively seems like it would have a large impact and slow things down because we have to walk everything before actually removing everything. I don't have a great sense for the practical impact of this though.

Copy link
Member

Choose a reason for hiding this comment

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

An alternative to this I think would be to perform the walk once, collect a list of all paths to remove, then remove them all in a loop. That would mean we only have to walk once and should be similar in performance I think.

fn rm_rf_glob(
pattern: &Path,
config: &Config,
progress: &mut impl CleaningProgressBar,
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be ok to change this from impl Cleaning... to dyn Cleaning... since we don't need the monomorphization aspect here per se

@ehuss
Copy link
Contributor

ehuss commented Jan 4, 2022

Just to echo some of Alex's comments, can you do some benchmarking and report if there is a performance hit with this? I think it would be good to test with some medium-ish sized projects, and on different systems (windows in particular has some slow fs behaviors). A small hit is fine, but if this makes cargo clean twice as slow, that might be concerning.

@theo-lw
Copy link
Contributor Author

theo-lw commented Jan 4, 2022

I'll do some benchmarking :) didn't realize that Windows had some peculiarities

theo-lw and others added 3 commits January 5, 2022 10:32
Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
@theo-lw
Copy link
Contributor Author

theo-lw commented Jan 5, 2022

Running cargo clean on rust-analyzer on Windows:

Before these changes:

Screen Shot 2022-01-05 at 1 16 10 AM

After these changes:

Screen Shot 2022-01-05 at 1 22 50 AM

So it looks like there is a performance regression of ~12% on Windows.

Running cargo clean on rust-analyzer on my mac:

Before these changes:

Screen Shot 2022-01-05 at 12 08 46 PM

After these changes:

Screen Shot 2022-01-05 at 12 25 35 PM

Performance doesn't have seemed to change much on my mac.

I'll experiment with collecting the paths into a vector.

@ehuss ehuss added the T-cargo Team: Cargo label Mar 30, 2022
@ehuss
Copy link
Contributor

ehuss commented Mar 30, 2022

I did some testing on various systems and different project sizes, and got roughly the same performance hit that you mentioned (ranging from 0 to 10%). The small performance hit is a bit unfortunate, but overall I don't think will be noticed much. I'm a little concerned for using cargo over a slow network connection, as I think this could tick quite frequently. I think there can possibly be followup in the future if that turns into a serious concern. Another possibility is to explore deleting files in parallel.

@rust-lang/cargo I'm going to just do a quick fcp check since this changes the output of a stable command, and there is a small performance hit.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Mar 30, 2022

Team member @ehuss has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels Mar 30, 2022
@rfcbot
Copy link
Collaborator

rfcbot commented Mar 31, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period FCP complete to-announce and removed final-comment-period FCP — a period for last comments before action is taken labels Apr 10, 2022
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 10, 2022

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@weihanglo
Copy link
Member

Just posted the possible extensions as a new issue (#10552). I am going to merge this PR.

@bors r+

@bors
Copy link
Contributor

bors commented Apr 10, 2022

📌 Commit 60cfe7e has been approved by weihanglo

@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 Apr 10, 2022
@bors
Copy link
Contributor

bors commented Apr 10, 2022

⌛ Testing commit 60cfe7e with merge f51e799...

@bors
Copy link
Contributor

bors commented Apr 10, 2022

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing f51e799 to master...

@bors bors merged commit f51e799 into rust-lang:master Apr 10, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 14, 2022
Update cargo

11 commits in e2e2dddebe66dfc1403a312653557e332445308b..dba5baf4345858c591517b24801902a062c399f8
2022-04-05 17:04:53 +0000 to 2022-04-13 21:58:27 +0000
- Part 6 of RFC2906 - Switch the inheritance source from `workspace` to… (rust-lang/cargo#10564)
- Part 5 of RFC2906 - Add support for inheriting `rust-version` (rust-lang/cargo#10563)
- Add support for rustc --check-cfg well known names and values (rust-lang/cargo#10486)
- Reserve filename `Cargo.toml.orig` in `cargo package` (rust-lang/cargo#10551)
- Retry command invocation with argfile (rust-lang/cargo#10546)
- Add a progress indicator for `cargo clean` (rust-lang/cargo#10236)
- Ensure host units don't depend on Docscrape units, fixes rust-lang/cargo#10545 (rust-lang/cargo#10549)
- Fix docs: Bindeps env vars are passed to build script at runtime (rust-lang/cargo#10550)
- Part 4 of RFC2906 - Add support for inheriting `readme` (rust-lang/cargo#10548)
- Part 3 of RFC2906 - Add support for inheriting `license-path`, and `depednency.path` (rust-lang/cargo#10538)
- Bump to 0.63.0, update changelog (rust-lang/cargo#10544)
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2022
Update cargo

11 commits in e2e2dddebe66dfc1403a312653557e332445308b..dba5baf4345858c591517b24801902a062c399f8
2022-04-05 17:04:53 +0000 to 2022-04-13 21:58:27 +0000
- Part 6 of RFC2906 - Switch the inheritance source from `workspace` to… (rust-lang/cargo#10564)
- Part 5 of RFC2906 - Add support for inheriting `rust-version` (rust-lang/cargo#10563)
- Add support for rustc --check-cfg well known names and values (rust-lang/cargo#10486)
- Reserve filename `Cargo.toml.orig` in `cargo package` (rust-lang/cargo#10551)
- Retry command invocation with argfile (rust-lang/cargo#10546)
- Add a progress indicator for `cargo clean` (rust-lang/cargo#10236)
- Ensure host units don't depend on Docscrape units, fixes rust-lang/cargo#10545 (rust-lang/cargo#10549)
- Fix docs: Bindeps env vars are passed to build script at runtime (rust-lang/cargo#10550)
- Part 4 of RFC2906 - Add support for inheriting `readme` (rust-lang/cargo#10548)
- Part 3 of RFC2906 - Add support for inheriting `license-path`, and `depednency.path` (rust-lang/cargo#10538)
- Bump to 0.63.0, update changelog (rust-lang/cargo#10544)
@ehuss ehuss added this to the 1.62.0 milestone Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge FCP with intent to merge finished-final-comment-period FCP complete S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-cargo Team: Cargo to-announce
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Progress to cargo clean
7 participants