Closed
Description
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.