#[cold]
is basically direct map to llvm's calling convention.
Do note that it affects how function is invoked (including how registers are preserved) hence inline
is unlikely to make any sense for it. If it is just trivial getter (one line) then you might as well just use inline(always)
instead of cold
to just eliminate function call (well hopefully)
P.s. I actually suspect cold
doesn't really automatically gets you branch prediction hint. It is a separate matter that can be achieved with likely
/unlikely
which are yet to be added in stable std.
But compiler can probably optimize it on its own if it sees branch with just cold
function, although I would just suggest check assembly for particular case
P.s.s. On a bit of philosophy cold
and inline
logically makes a little sense. When you invoke cold
function you should already brace for performance impact of it hence trying to mitigate it by inlining is not necessary a fitting to the goal here (i.e. you assume that function is not going to be called normally)