Can You RVO?Bloomberg Finance L.P. All rights reserved. © 2024 Bloomberg Finance L.P. All rights reserved. Can you RVO? Using Return Value Optimization for Performance in Bloomberg’s C++ Codebases CppCon 2024 September Bloomberg Finance L.P. All rights reserved. © 2024 Bloomberg Finance L.P. All rights reserved. Can You RVO? How many people here have heard about “Return Value Optimization”? 2 How many people here are All rights reserved. © 2024 Bloomberg Finance L.P. All rights reserved. Return Value Optimization (RVO) 5© 2018 Bloomberg Finance L.P. All rights reserved. Agenda Questions at the end Source: PresentationGO0 码力 | 84 页 | 9.98 MB | 6 月前3
Things Happening in SG14attributes • [[no_copy]] • Annotate types and function arguments with [[no_copy]] if only move and RVO are acceptable. Example: [[no_copy]] SomeContainerFoo(); [[no_copy]] SomeType Bar(); categories 97P2966 requests: attributes • [[rvo]] • Annotate functions with [[rvo]] to ensure calls to these functions only compile if used in a RVO situation • Analogous to [[no_copy]] • There might might be a basis in P2025 and in Clang's non-standard [[musttail]] attribute • Example: [[rvo]] X f(); // ... auto x0 = f(); // Ok X x1; // x1 = f(); // not Ok 98P2966 requests: attributes • [[side_effect_free]] 0 码力 | 148 页 | 1009.97 KB | 6 月前3
The Roles of Symmetry And Orthogonality In DesignSymmetry • C++ Techniques to cheat object lifecycle symmetry: • (Named-)Return Value Optimization (RVO, NRVO) to transfer instance • “Pilfer” or transfer object state: • xvalues (&&) (since C++11) • std::move<> Member-function binary operator overloads (left-operand is always *this) • (Named-)Return Value Optimization (RVO, NRVO) to transfer instance • xvalues (&&) (since C++11) to pilfer or transfer instance state • std::move<> unspecified state”) • Temporary objects (i.e., prvalue “materialization”) • xvalues (“eXpiring values”) • RVO, NRVO (Named-Return Value Optimization) Review: Storage Duration • C++ Storage Duration is one of:0 码力 | 151 页 | 3.20 MB | 6 月前3
Hidden Overhead of a Function APImaterialized until needed, and then it is constructed directly into the storage of its final destination. 72RVO: how it works Itanium C++ ABI 3.1.3.1 Non-trivial Return Values If the return type is a class type the function prototype, preceding all other parameters, including the this and VTT parameters. 73RVO: how it works Itanium C++ ABI 3.1.3.1 Non-trivial Return Values If the return type is a class type VTT parameters. It’s an output parameter done right by the compiler, and only when necessary! 7475RVO: inserting a function result into a container #includestruct large { large(); 0 码力 | 158 页 | 2.46 MB | 6 月前3
The Surprising Costs of Voidnot use a local vector and return it, you say? I wonder too… I see this pattern quite a lot… Is RVO misunderstood?3031 « Create », like « get », is a suspicious fit for void return types. Likewise for ~Noisy() We have one less variable around, and since we’re initializing n with the return value of f, RVO kicked in!8081 Noisy() Noisy(Noisy&&) ~Noisy() ~Noisy()82 Noisy() Noisy(Noisy&&) ~Noisy() ~Noisy()0 码力 | 189 页 | 60.10 MB | 6 月前3
Back To Basics: Rvalues and Move Semanticsalmost dead object * Some of the redundant inefficient copies can be avoided by the compiler, using RVO (Return Value Optimization) or NRVO (Named Return Value Optimization). But not all.Recap questions0 码力 | 80 页 | 740.53 KB | 6 月前3
Some Things C++ Does Rightonly does a single pass • … and might at the same time benefit from the return value optimization (RVO) better 51A word about beauty and elegance templateauto f_g_x(F f, G g) { 0 码力 | 228 页 | 2.47 MB | 6 月前3
Object Lifetime: From Start to Finish____________ val = o.getFoo(); } 1 2 3 4 5 6 7 8 9 Foo Foo 1/9 Return Value Optimization (RVO) Temporary is initialized directly in val’s storagehttps://abseil.io/tips/101 Return Initialize0 码力 | 214 页 | 9.34 MB | 6 月前3
Comprehensive Rust(简体中文) 202412Rust 编译器能够执行返回值优化 (RVO)。 • In C++, copy elision has to be defined in the language specification because constructors can have side effects. In Rust, this is not an issue at all. If RVO did not happen, Rust0 码力 | 359 页 | 1.33 MB | 10 月前3
Comprehensive Rust(繁体中文)Rust 編譯器可以執行回傳值最佳化 (RVO)。 • In C++, copy elision has to be defined in the language specification because constructors can have side effects. In Rust, this is not an issue at all. If RVO did not happen, Rust0 码力 | 358 页 | 1.41 MB | 10 月前3
共 13 条
- 1
- 2













