Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs about performance and Iterator::map to [T; N]::map #87609

Merged
merged 1 commit into from
Jul 30, 2021

Conversation

LukasKalbertodt
Copy link
Member

This suboptimal code gen for some usages of array::map got a bit of
attention by multiple people throughout the community. Some cases:

My guess is that this gets the attention it gets because in JavaScript
(and potentially other languages), a map function on arrays is very
commonly used since in those languages, arrays basically take the role
of Rust's iterator. I considered explicitly naming JavaScript in the
first paragraph I added, but I couldn't find precedence of mentioning
other languages in standard library doc, so I didn't add it.

When array::map was stabilized, we still wanted to add docs, but that
somehow did not happen in time. So here we are. Not sure if this sounds
crazy but maybe it is worth considering beta backporting this? Only if
it's not a lot of work, of course! But yeah, stabilized array::map is
already in beta and if this problem is really as big as it sometimes seems,
might be worth having the docs in place when 1.55 is released.

CC @CryZe

r? @m-ou-se (since you were involved in that discussion and the stabilization)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 29, 2021
@leonardo-m
Copy link

It could also be added a warning when the programmer attempts to use map on a sufficiently large array.

@m-ou-se
Copy link
Member

m-ou-se commented Jul 30, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jul 30, 2021

📌 Commit 5cc7702 has been approved by m-ou-se

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2021
@LukasKalbertodt
Copy link
Member Author

It could also be added a warning when the programmer attempts to use map on a sufficiently large array.

That would require us to set some kind of threshold, which is hard. And there are cases where map optimizes well even for large arrays, and others where it doesn't even for medium sized ones. So I'm not sure such a warning would really help. If anything, it could be a clippy lint.

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 30, 2021
…ocs, r=m-ou-se

Add docs about performance and `Iterator::map` to `[T; N]::map`

This suboptimal code gen for some usages of array::map got a bit of
attention by multiple people throughout the community. Some cases:

- rust-lang#75243 (comment)
- rust-lang#75243 (comment)
- https://www.reddit.com/r/rust/comments/oeqqf7/unexpected_high_stack_usage/

My *guess* is that this gets the attention it gets because in JavaScript
(and potentially other languages), a `map` function on arrays is very
commonly used since in those languages, arrays basically take the role
of Rust's iterator. I considered explicitly naming JavaScript in the
first paragraph I added, but I couldn't find precedence of mentioning
other languages in standard library doc, so I didn't add it.

When array::map was stabilized, we still wanted to add docs, but that
somehow did not happen in time. So here we are. Not sure if this sounds
crazy but maybe it is worth considering beta backporting this? Only if
it's not a lot of work, of course! But yeah, stabilized array::map is
already in beta and if this problem is really as big as it sometimes seems,
might be worth having the docs in place when 1.55 is released.

CC `@CryZe`

r? `@m-ou-se` (since you were involved in that discussion and the stabilization)
This was referenced Jul 30, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 30, 2021
Rollup of 9 pull requests

Successful merges:

 - rust-lang#86072 (Cross compiling rustc_llvm on Darwin requires zlib.)
 - rust-lang#87385 (Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default)
 - rust-lang#87547 (Add missing examples for NonNull)
 - rust-lang#87557 (Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic)
 - rust-lang#87559 (Tweak borrowing suggestion in `for` loop)
 - rust-lang#87596 (Add warning when whitespace is not skipped after an escaped newline)
 - rust-lang#87606 (Add some TAIT-related regression tests)
 - rust-lang#87609 (Add docs about performance and `Iterator::map` to `[T; N]::map`)
 - rust-lang#87616 (Fix missing word in rustdoc book)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f4dfb76 into rust-lang:master Jul 30, 2021
@rustbot rustbot added this to the 1.56.0 milestone Jul 30, 2021
@LukasKalbertodt LukasKalbertodt deleted the improve-array-map-docs branch September 10, 2021 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants