Skip to content

Performance of inlined code not as expected #24489

Closed
@tbu-

Description

@tbu-

I expect the following two snippets to have the same performance:

#[inline(always)]
fn decrement(val: u32) -> Option<u32> {
    if val != 0 {
        Some(val - 1)
    } else {
        None
    }
}

match decrement(a) {
    Some(aa) => /* do something */ {},
    None => /* do something else */ {},
}

and

if a != 0 {
    a - 1;
    /* do something */
} else {
    /* do something else */
}

The latter one has better performance in current Rust: Gist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationI-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions