Hidden Overhead of a Function API
Talkat CppCon 2024 · on Wednesday, 2024-09-18· at 09:00· Cottonwood 8/9, 6700 North Gaylord Rockies Boulevard·
summary
Examines concrete assembly and microbenchmarks across Clang GCC and MSVC on ARM and x86 and shows how signature choices matter: returning by value usually beats output parameters (measured 25% overhead for an out-param case), wrappers like std::unique_ptr can force memory temps (one case is 3x slower), calling conventions and ABI rules explain stray loads and moves, a small lazy wrapper implementation restores RVO and eliminates the extra work, and all investigations use Compiler Explorer and real instruction counts.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:25Functions and performance
- 3:12Performance beyond benchmarks
- 7:06Return values vs output params
- 12:51Return by value and C++ abstractions
- 23:07Return value optimization deep dive
- 28:15Output parameters in practice
- 29:48Pass by value vs reference
- 34:52Perfect forwarding costs
- 35:54Non-trivial types and references
- 36:17Span and trivial types
- 39:30Empty params and ABI quirks
- 43:04Parameter order and registers
- 47:42Array pointer pitfalls
- 50:34Limiting arguments for speed
- 55:13Key takeaways
- 56:41Q&A
related talks
04mZero-Overhead Compiler Pessimization
01h 03mto pass and return, the story of functions, values and compilers
49mThe Hidden Performance Price of C++ Virtual Functions
01h 03mUnlocking the value of C++20
08mOn "simple" Optimizations
01h 10mstd::function: a deep dive behind the curtain
32mOptimizing Away C++ Virtual Functions May Be Pointless
58mArgument Passing, Core Guidelines and Aliasing
