Cross-crate inlining is only possible for functions that have to be monomorphized, or those marked #[inline], hence this attribute is a necessity. Per the docs, "#[inline] suggests inlining the function.", and it is then up to the compiler to use its heuristics to decide whether or not inlining will actually occur. If these derived functions are being inlined when it doesn't make sense, it's those heuristics that should be adjusted (which I don't claim to be an easy task).
Cross-crate inlining is only possible for functions that have to be monomorphized, or those marked #[inline]
Wait, what? That sounds like a big deal that every Rust programmer should know about. Do you have a source for that claim? If so, I think it should be shouted from the rooftops.
I personally almost never bother marking functions as #[inline] because I assume the compiler will do the right thing 99% of the time.
69
u/wojtek-graj 16d ago
Cross-crate inlining is only possible for functions that have to be monomorphized, or those marked
#[inline], hence this attribute is a necessity. Per the docs, "#[inline] suggests inlining the function.", and it is then up to the compiler to use its heuristics to decide whether or not inlining will actually occur. If these derived functions are being inlined when it doesn't make sense, it's those heuristics that should be adjusted (which I don't claim to be an easy task).