Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make initialization in
OnceNonZeroUsize::get_or_try_init
#[cold]
.
In typical use, the Some branch is going to be taken extremely frequently but the None branch is only going to be taken once (or a very small number of times) at startup. If `get_or_try_init` is in a performance-sensitive segment of code, then it is important that `get_or_try_init` be inlined and that the compiler understands that the Some branch is (much) more likely than the None branch. When this happens, the call site basically becomes a load followed by a conditional jump that is basically never taken; which is ideal. When `get_or_try_init` is used in many places in the user's code, it is important to avoid inlining any of the None branch into the call sites. Unfortunately, the Rust compiler is sometimes not good at recognizing that code that calls a #[cold] function unconditionally must be cold itself. So, sometimes it isn't enough to mark our f as `#[cold] #[inline(never)]`. Move the entire body of the None branch into a function that is marked because some post-inlining optimization passes in the compiler seem to not understand `#[cold]`, and because we don't want any part of that branch to be in the calling code.
- Loading branch information