rust-lang / rust-lang/rust-clippy
Don't use `join_all` on `JoinHandle`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
The join_all method is used to run multiple futures concurrently by polling all of them simultaneously. However, if used together with tokio::spawn, it provides no advantage over a simple loop, and has a performance impact since the join_all does extra work to poll all of them simultaneously.
Lint Name
join-all-joinhandles
Category
perf
Advantage
- Using
join_allon a vector ofJoinHandleis inefficient. - Using
join_allmakes it easy to ignore errors becauseVec<Result<...>>is not#[must_use].
Drawbacks
Calling join_all is shorter.
Example
let join_handles: Vec<JoinHandle<T>> = ...;
join_all(join_handles);
Could be written as:
let join_handles: Vec<JoinHandle<T>> = ...;
for handle in join_handles {
handle.await;
}
Note that the handle.await will trigger a #[must_use] warning in the above, which is not triggered in the original example.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the implementation entry point for the join-all-joinhandles lint in rust-clippy and review how existing performance lints inspect join_all and JoinHandle. Done means the lint detects the described pattern, recommends awaiting handles in a loop, and preserves the #[must_use] warning behavior shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100