-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Slow compilation of async fn that creates a vector with many Strings created from string literals, even with no .await #115327
Copy link
Copy link
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-compilememIssue: Problems and improvements with respect to memory usage during compilation.Issue: Problems and improvements with respect to memory usage during compilation.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-compilememIssue: Problems and improvements with respect to memory usage during compilation.Issue: Problems and improvements with respect to memory usage during compilation.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await
Type
Fields
Give feedbackNo fields configured for issues without a type.
Build with
cargo build. I'm using Rust 1.72 on aarch64-apple-darwin.In addition to the slow compilation time, I also see large memory usage. With 2500 lines, my OS reported
rustcas consuming 20GB.Exploration
Different versions
There was no obvious correlation.
Different numbers of lines
This appears to show time is proportional to (number of lines)^2
String slices
Switching to returning a
&'static strinstead ofStringresulted in fast compilation (<250 ms).Using a function
Creating a helper function and calling it inside of
vec![]resulted in fast compilation (<250 ms).Using another method
Switching to returning a
usizeinstead of aStringhas reduced compilation time but still surprisingly slow (2.5 sec).Avoiding
async fnRemoving
asyncfrommake_menageriehas reduced compilation time (<750 ms)Test case generation
For trying different things, I used two files
main.rs
And to generate 2500 lines: