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

Simple async wrapper doubles the size of a future #72454

Closed
jimblandy opened this issue May 22, 2020 · 1 comment
Closed

Simple async wrapper doubles the size of a future #72454

jimblandy opened this issue May 22, 2020 · 1 comment
Labels
A-async-await Area: Async & Await C-bug Category: This is a bug. I-heavy Issue: Problems and improvements with respect to binary size of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jimblandy
Copy link
Contributor

I'm using the following wrapper function:

pub async fn log_error<F>(future: F)
where
    F: Future<Output = Result<(), Box<dyn Error + Send + Sync + 'static>>>
{
    if let Err(err) = future.await {
        print_error(err);
    }
}

Using std::mem::size_of_val, the size of any future returned by this function is a bit more than twice the size of the future passed to it. This is a pretty severe penalty for a simple helper function.

@jimblandy jimblandy added the C-bug Category: This is a bug. label May 22, 2020
@LeSeulArtichaut LeSeulArtichaut added the I-heavy Issue: Problems and improvements with respect to binary size of generated code. label May 22, 2020
@jonas-schievink jonas-schievink added A-async-await Area: Async & Await T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 22, 2020
@jonas-schievink
Copy link
Contributor

Duplicate of #62958

@jonas-schievink jonas-schievink marked this as a duplicate of #62958 May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await C-bug Category: This is a bug. I-heavy Issue: Problems and improvements with respect to binary size of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants