Rust's derive often implies inline

47 points by yossarian


kornel

I'd expect #[inline] on Ord and Eq, maybe Clone, but having it on Debug is surprising. I put #[cold] on my fn fmt implementations!

ralfj

This seems worth a bugreport in the rust-lang/rust repo. We've changed the #[inline] on Debug in the past and we can change it again. It's just hard to pick a good trade-off between code size, compile time, and run time.

aw1621107

For what it's worth this 2023 PR is the one that added #[inline] to Debug because it generally resulted in better (!) benchmark numbers. Interestingly, there was an experimental PR that only emitted the attribute on structs with <=5 fields and it resulted in a performance regression compared to always emitting the attribute.

tsion

#[inline] is just a hint

This is not quite true. It also enables cross-crate inlining, which is always possible for generics but not possible for non-generic functions by default. It's too bad we don't have a #[can_inline] that omits the hint part.