rust-lang / rust-lang/rust-clippy
Suggest `#[inline]`ing `Iterator::next` on concrete types
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
Very often, the performance of iterators depends on Iterator::next getting inlined.
That's usually not a problem, because iterators are often generic, and thus the monomorphization is available to be inlined.
However, non-generic iterators can't cross-crate inline by default, so it would be good to suggest marking them #[inline].
Lint Name
non_inlined_concrete_iterator
Category
perf
Advantage
Allows for the possibility of improved optimizations at the call site.
Drawbacks
All the usual drawbacks of inlining apply, like potentially slower compilation or increased binary size.
This might not be necessary for iterators not exported from their crate.
Example
impl Iterator for EscapeDefault {
type Item = u8;
fn next(&mut self) -> Option<u8> {
self.range.next().map(|i| self.data[i as usize])
}
}
Could be written as:
impl Iterator for EscapeDefault {
type Item = u8;
#[inline]
fn next(&mut self) -> Option<u8> {
self.range.next().map(|i| self.data[i as usize])
}
}
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
Review the proposed non_inlined_concrete_iterator lint and its EscapeDefault example first. Establish how the lint should identify concrete iterator implementations and what diagnostic should recommend; done means the lint's behavior matches the stated example and accounts for the listed inlining drawbacks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100