dimforge / nalgebra

Linear algebra library for Rust.
https://nalgebra.org
Apache License 2.0
4.02k stars 481 forks source link

#[inline] on generic functions #312

Open milibopp opened 6 years ago

milibopp commented 6 years ago

Should #[inline] tags be present on generic functions? As far as I know, they don't actually help with inlining, since generic functions are instantiated for each type during monomorphization. However, they may actually incur a cost on compile times, which are quite long for nalgebra.

The above statements should be tested with benchmarks, before doing anything about this, of course. Is there an argument for why the annotations should stay or are they just present out of habit?

EDIT: typo

jswrenn commented 6 years ago

As far as I know, they don't actually help with inlining, since generic functions are instantiated for each type during monomorphization.

My intuition was that although generic functions are instantiated for each type during monomorphization, inlining attributes should apply to those instantiations. After a brief experiment on Compiler Explorer, I'm less sure of that position; ample application of #[inline(never)] did not seem to have any effect.

sebcrozet commented 6 years ago

I've not made any benchmarks on this so far, but that comment on a rust-clippy issue may support the intuition of @jswrenn .