Skip to content

Inconsistent inlineing of Iterator Adaptors - Missed Optimizations #47461

Open
@jonasbb

Description

@jonasbb

While profiling some rust code of me, I noticed that the following pattern does not optimize well:

vec![1,2,3,4]
    .into_iter()
    .map(|v| ...)
    .skip_while(|v| ...)

skip_while is implemented using find and find is implemented using try_fold. The functions SkipWhile::next() and Iterator::find() use the #[inline] annotation. The function Map::try_fold() does not. This means that Map::try_fold() will not be inlined.

I started looking at the source code and inlineing of iterators seems to follow no rule. I could not find any bug reports related to this.

Some iterators like Cloned do not have any function marked as inline. Not even next() is marked as inline.

The PR introducing try_fold does not give justification why some try_folds are inline and some are not.

The methods len and is_empty of ExactSizeIterator's are also not marked as inlineable, even though they are always implemented as pass-through to the underlying iterator.

If desired I can prepare a pull request to mark those functions as inlineable. Is there a list of functions for the iterator traits (e.g., Iterator, ExactSizeIterator) which should be inline/not be inline?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-iteratorsArea: IteratorsC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions