Provide optimizer hints as “unlikely” for panicking paths.
Motivation
Unlike exception (in other languages), panics are used for critical (logic) errors and is unlikely to be called. We can attempt to improve the performance of unwrap() with this.
I consider this RFC to be simple, or this maybe doesn’t need a RFC at all. Comments on improving or expanding this are welcome, as well as discussing potential issues of this RFC.
This doesn’t seem like RFC territory, since it’s a relatively small internal change that has no observable behavior aside from code quality. Furthermore, there’s nothing to build consensus about, it’s a matter of data: someone needs to implement this and show that it performs better.
I was under the impression that panics use landing pads similar to C++ exceptions. If that’s the case, then they should already be completely outside of the normal control flow.
edit: Or do you mean adding “unlikely” to branches that start a panic? That seems sensible.
What the #[cold] that sfackler mentioned turns into in LLVM:
This attribute indicates that this function is rarely called. When computing edge weights, basic blocks post-dominated by a cold function call are also considered to be cold; and, thus, given low weight.