Inline attributes can be added to functions and methods. As a library author, when should I use them?
I feel like the compile probably knows better than me when inlining is beneficial or not, so I don’t use
#[inline(never)]. (I guess I only would if measured evidence shows that it helps significantly when trying to optimize something.) But
#[inline] is less clear-cut. There can be no cross-crate inlining without it, and cross-crate is the main usage of a library. So I tend to add it to functions that I feel are “small enough”, but that’s kinda random.
Is any use of
#[inline] without benchmarks premature optimization? Or should I
#[inline] all the things and let the compiler figure it out? Or is there a better criteria for something in between?