proomt

Search

Search posts, papers, and topics

All posts

Lobsters2 min readintermediate

Rust's derive often implies inline

Summary

Rust's `#[derive]` macros automatically add `#[inline]` to generated trait implementations. While helpful for trivial code, large derived `Debug` impls can bloat binaries, and you can suppress this with a custom proc macro that uses `#[inline(never)]`.

  • `#[derive]` generated impls are annotated with `#[inline]` by the compiler.
  • Inlining large derived `Debug` implementations can noticeably increase binary size (e.g., ~160 KB).
  • The compiler does not cap inlining of derived code, so the hint may be counter‑productive.
  • A custom proc macro that adds `#[inline(never)]` can prevent the unwanted size growth.

Rust developers who care about binary size and compile‑time performance should know that derived inlining isn’t always beneficial.

6/10

Related reading

  1. Cylic trait implementations: motivation

    The post introduces the problem of cyclic trait implementations in Rust, showing how allowing certain cycles could enable “perfect derive” that derives traits based on field types rather than generic bounds. It also explains why naïvely accepting any cycle is unsound, especially with supertraits, and outlines the need for a principled solution.

    Mozilla Automation Teamsmallcultfollowing.com9 minHN1