logoalt Hacker News

Rust's derive often implies inline

67 points • by woodruffw • last Sunday at 1:27 AM • 8 comments • view on HN

Comments

vlovich123 • today at 1:48 PM

I feel like Debug should be lazily emitted altogether when it’s first used - just a special marker that’s never expanded since 99% of the Debug implementations aren’t used and having the rest marked #[cold] as inline is obviously wrong. Of course implementing it in practice sounds exceptionally difficult.

That being said, even the justifying performance improvement PR was itself a mix of improvements and regressions

Sharlin • today at 12:56 PM

I’m fairly convinced that Debug should never be inlined. Display probably neither, the fmt machinery is heavy enough that not inlining is probably not a bottleneck even in serialization-heavy workloads. I’ve had to #[inline(never)] some of my own Debug/Display impls, shrinking the binary by tens of kilobytes (out of a few hundred, so relatively a significant reduction).

➕ show 1 reply
zamazan4ik • today at 1:20 PM

Or just try to avoid all of these optimization guesses by using Profile-Guided Optimization (PGO), that inserts/deletes all inlines based on actual application runtime profile.

➕ show 1 reply
api • today at 2:01 PM

There's a joke that the LLVM heuristic for whether to inline a function is "return true;" LLVM tends to inline aggressively.

You can control this behavior with opt level "s" or "z" or "#[inline(never)]", but be aware that too little inlining can have large negative performance impacts.

It's hard to get inlining exactly right without profile guided optimization.