-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-coroutinesArea: CoroutinesArea: CoroutinesAsyncAwait-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-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.T-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.
Description
Generator optimization in #60187 by @tmandry reused generator locals, but arguments are still duplicated whenever used across yield points.
For example (playground):
#![feature(async_await)]
async fn wait() {}
async fn test(arg: [u8; 8192]) {
wait().await;
drop(arg);
}
fn main() {
println!("{}", std::mem::size_of_val(&test([0; 8192])));
}
Expected: 8200
Actual: 16392
When passing in futures, the future size can grow exponentially (playground):
#![feature(async_await)]
async fn test(_arg: [u8; 8192]) {}
async fn use_future(fut: impl std::future::Future<Output = ()>) {
fut.await
}
fn main() {
println!(
"{}",
std::mem::size_of_val(&use_future(use_future(use_future(use_future(use_future(
use_future(use_future(use_future(use_future(use_future(test(
[0; 8192]
))))))
))))))
);
}
Expected: 8236
Actual: 8396796
I didn't find any note on this. But given how common arguments are used, I think it might be useful if they are included in the optimization.
cramertj, ivan, tmandry, patrickfreed, Kobzol and 21 morehorazont, yhx-12243, Sherlock-Holo, MihaelBercic and CathalMullan
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-coroutinesArea: CoroutinesArea: CoroutinesAsyncAwait-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-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.T-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.