Skip to content

Simple async wrapper doubles the size of a future #72454

@jimblandy

Description

@jimblandy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitC-bugCategory: This is a bug.I-heavyIssue: 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions