rust-lang / rust-lang/rust-clippy

Don't use `join_all` on `JoinHandle`

Open
#9,843 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
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_all on a vector of JoinHandle is inefficient.
  • Using join_all makes it easy to ignore errors because Vec<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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.