Skip to content

Compiler optimization suggestion - Iter<String>.collect::<Vec<String>>().join("") #95165

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

Closed
yoav-lavi opened this issue Mar 21, 2022 · 4 comments
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.

Comments

@yoav-lavi
Copy link
Contributor

yoav-lavi commented Mar 21, 2022

Hi,

I've opened this issue for clippy: rust-lang/rust-clippy#8570 wherein a collect::<Vec<String>>().join("") operation on an Iter<String> can be expressed as collect::<String>() which is more performant.

I wanted to put this here as well as I think this may be something that can also be optimized by the compiler (by replacing the former with the latter) since the output should always be equivalent and the latter option is more performant.

See cases of this happening in the wild here (GitHub CS Beta) or here (Sourcegraph)

I'm learning Rust so please let me know if I'm missing something, thank you!

@leonardo-m
Copy link

I wanted to put this here as well as I think this may be something that can also be optimized by the compiler

I think rustc creators don't like (or don't have time) to add similar special cased optimizations. In past years I have suggested many times spot optimizations for rustc and I think they were never implemented.

@blyxyas
Copy link
Member

blyxyas commented Jan 13, 2023

@rustbot label: +S-inactive

@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Jan 13, 2023
@blyxyas
Copy link
Member

blyxyas commented Jan 13, 2023

A lint for clippy is already merged (rust-lang/rust-clippy#8579) I think this issue can be closed as has had no updates for 9 months and will probably not be re-implemented in the Rust compiler, as it is already in Clippy.

@yoav-lavi
Copy link
Contributor Author

For anyone seeing this in the future - Please take a look at the comments here: rust-lang/rust-clippy#8579
This change being more performant depends on the target arch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

No branches or pull requests

4 participants