-
Notifications
You must be signed in to change notification settings - Fork 906
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
cargo fmt --all is slow in a workspace project #4247
Comments
Originally filed as rust-lang/cargo#8345. |
Closing as the problem was tracked down to a cargo issue after all. |
This is because rustfmt uses By default, rustfmt uses the offline mode of |
As noted by @ehuss in rust-lang/cargo#8345 (comment):
|
@mzabaluev - does your project have non-workspace member local/path-based dependencies that you also want to format? Running From the --all Format all packages, and also their local path-based dependencies FYI the multiple |
@calebcartwright Thanks for the tip! One of our larger projects does use path-based dependencies pulled in by a git submodule, but these can be format-checked in a CI workflow of that submodule's repository. |
Great! In that case I'd recommend just running |
It adds nothing useful to this project and furthermore, slows down the test run. Per suggestion in rust-lang/rustfmt#4247 (comment)
@calebcartwright I can help rework the logic for the |
It adds nothing useful: cargo fmt checks all legitimate workspace members, and for the chain-deps we have a CI workflow in its own reposotiry. Moreover, the --all flag slows down the test run. Per suggestion in rust-lang/rustfmt#4247 (comment)
@ehuss - sure! The Additionally, it would also be really helpful for rustfmt if we can get a solution/alternative to rust-lang/cargo#7483 so that we can always use |
Ran into this today as well, and was confused both why This was on Windows (though through Git Bash) in a workspace of 28 crates. $ time cargo fmt --all
real 0m20.996s
user 0m0.000s
sys 0m0.000s
$ time cargo fmt
real 0m1.298s
user 0m0.000s
sys 0m0.016s All of our crates are in our root |
I think the main issue here is the disconnect between what the BackgroundThere's only a few use cases I recall where the
I suspect that the majority of instances where folks are using the
Accordingly, in order to support the second (and third) use case, AIUI, running Next StepsWe've tried updating the help text for the Perhaps some non-mutually exlusive actions we could consider:
|
It adds nothing useful to this project and furthermore, slows down the test run. Per suggestion in rust-lang/rustfmt#4247 (comment)
There are breaking changes planned for v2.0 sometime soon, right? If that can include the CLI interface, I think (Whether to change the default to not do the entire workspace and add a |
(Actually, even if there are no breaking changes, it'd be nice to rename this flag and add a deprecated alias for it, maybe even hiding that from the help text in the future). |
@calebcartwright Since it looks like rust-lang/cargo#8994 is probably going in the right direction, maybe it'd make sense to start up a draft PR here that uses it when available so we can maybe even fix this on the next beta (which I think is Dec 31st). What do you think? If you're busy I can try to find some spare cycles to write it up, though you know the code better than I do. |
Won't commit to any target timeframe just yet, especially given the holidays, but yes will try to get this out soon once possible to proceed. Unfortunately due the various non-rustup channels through which rustfmt is distributed and can be used there will be a bit of extra complexity to handle working with older versions of cargo that may not the newer changes. I'm also not sure if the cargo_metadata crate will need to first be updated as well before we can start taking advantage of rust-lang/cargo#8994 |
Yeah, I think we'll probably have to track whether we see a local dependency ( I'll take a look at adding support to |
There's a promising new upstream PR here that might unblock this: rust-lang/cargo#9024 |
metadata: Supply local path for path dependencies This is potentially a simpler way to address #7483 than #8988. /cc rust-lang/rustfmt#4247 Fixes #7483.
rust-lang/cargo#8994 was merged, and will land (if all goes according to plan) in 1.51. The change to |
This slows down the job considerably with no added benefit, see rust-lang/rustfmt#4247 (comment)
oli-obk/cargo_metadata#149 has been merged @calebcartwright, so I think we now have all we need to start working on an implementation in |
@calebcartwright I believe the updated |
Thanks @jonhoo, planning on looking at it this week |
@calebcartwright Gentle bump on this — have you had a time to think more about this vs #4722? |
@jonhoo - stretched rather thin and having to juggle 20 different things. This is on the top of my list for whenever I get a chance to actually work on some rustfmt development, but right now my limited rustfmt bandwidth is preoccupied with other general support and maintenance activities. I also want to stress that there is no either/or here. We're definitely going to make this change, and there's a good chance we'll probably go forward with #4722 as well. However, really important to note that #4722 would only be at play with explicit workspaces, but if you have an explicit workspace you do not need to use |
The resolution for this will be in the next release. Purely anecdotal data points on my slow machine so treat them as such, but suffice to say that folks using |
Available on nightly as of |
Run `cargo fmt` without `--all` According to [this thread](rust-lang/rustfmt#4247), the `--all` flag causes `cargo-fmt` to call `cargo metadata` for each package in the workspace, which requires a fresh cargo registry locally. However, `cargo fmt --all` is redundant in most cases, as it is in ours. Removing it should speed up the build step. See merge request dfinity-lab/public/ic!3054
Problem
cargo fmt --all
runs unexpectedly slow in a medium-sized workspace project.Steps
cargo fmt --all
on the repository.This run shows rustfmt and/or cargo pausing for more than 20 s before producing any output in verbose mode. Seen with timestamps in the raw log:
Notes
Output of
cargo version
:cargo 1.44.0 (05d080faa 2020-05-06)
Output of
rustfmt --version
rustfmt 1.4.14-stable (e417356 2020-04-21)
Virtual environment information from GitHub workflow:
Operating System
Ubuntu
18.04.4
LTS
Virtual Environment
Environment: ubuntu-18.04
Version: 20200518.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu18/20200518.1/images/linux/Ubuntu1804-README.md
The text was updated successfully, but these errors were encountered: