Inline experiment

I recently did an experiment using #[inline] on functions I thought should be inlined.
It didn't make any difference I could measure. What did make a substantial difference was using #[inline(never)] which resulted in a measurable loss of performance of about 25%.

My conclusion is that in most cases the compiler is likely to make good choices on inlining and it is unlikely that you need to bother with any manual tuning, but I would be interested to hear if anyone has a different experience.

1 Like

Are you sure you are doing everything correctly. From the reference:

#[inline]. This suggests that the function should be inlined, including across crate boundaries.

If you are not using functions marked as #inline across the crates borders then it wouldn't change anything, most of the time.


This mirrors my experience. In a mono-crate project, #[inline] has next to no observable effect. It might be more noticeable on multi-crate projects.


This was within a crate. I don't think I have any code where inlining across a crate boundary would have any significant effect.

( I think I was doing it right, it was just that my "suggestions" were functions that the compiler was already inlining automatically anyway, so it didn't make any difference ).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.