Skip to content

Implement attributes for branch weight #11092

Closed
@kvanbere

Description

@kvanbere

The cold attribute exists for functions, but one might want to put weights on branches. This could have 3 forms; weight=N where N is 0-1, likely (1) and unlikely (0).

LLVM understands these annotations on branches already and can use these to fine-tune assembly to reduce branch mis-predictions. By nature, these could be used extensively in the standard library.

ie

match leaf {
    #[likely]
    Some(x) => recurse(x),
    None => {
        // do stuff that doesn't make sense to be in a cold fn
        ...
    }
}

There have been cases in Haskell libraries where changing the order of ADTs can increase performance by around 20% because branches are guessed differently by the compiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-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