-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Description
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?