| ▲ | Rust's derive often implies inline(yossarian.net) | |||||||||||||||||||||||||||||||
| 70 points by woodruffw 4 days ago | 10 comments | ||||||||||||||||||||||||||||||||
| ▲ | vlovich123 2 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||
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 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
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). | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | scottlamb 21 minutes ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I wonder if they ever considered a table-driven approach for `#[derive(Debug)]`, as `facet` [1] does. That would have been my first instinct for something this formulaic where binary size and compilation time matter more than execution speed. But my impression is facet hasn't quite realized its promise on those fronts, so maybe the table-driven approach in std was similarly tried and rejected. | ||||||||||||||||||||||||||||||||
| ▲ | zamazan4ik 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | api an hour ago | parent | prev [-] | |||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||