Partial inlining
15 points by fanf
15 points by fanf
Article is light on the specifics of this, how and when the compiler does it/chooses to do it, and how you can induce the compiler to do this for you.
If you’re using an llvm-based compiler, you can influence this with judicious use of llvm function attributes. In rust, I use a mix of #[inline_always] on the outer function, (nested) function/lambda declarations with #[inline(never)] or #[cold] as needed (llvm doesn’t use coldcc abi to call these, so it can be abused to do what you need, especially with rust’s lack of likely/unlikely hints in stable, which will probably never change).
Matt put up an example of outlining a slow path years ago on his blog but I can’t find it now. Basically extract the slow path into an immediately invoked lambda annotated with [cold]. I’m surprised he didn’t reference that post here.