Rust's derive often implies inline
4 days ago
- Rust's derive macros for core traits like Debug, Display, and Clone automatically emit #[inline] on generated implementations.
- While usually beneficial for trivial code, #[inline] can cause significant binary size bloat when derived implementations (especially Debug) are deeply nested and called frequently.
- An example error hierarchy with nested Debug derives generates a large amount of inlinable code, which can expand binary size substantially (e.g., 160KB reduction in uv by preventing inlining).
- The compiler seemingly does not apply a size or frequency limit to inlining of Debug implementations, leading to surprising cumulative size costs.