3 ms·
Does the C++ ABI also spill 24-byte objects to the stack for each call? I guess I don't expect std::string or std::function parameters to be fast but it's stil
by loeg 3y ago
Does the C++ ABI also spill 24-byte objects to the stack for each call? I guess I don't expect std::string or std::function parameters to be fast but it's still surprising.
- pclmulqdq 3y agoSpilling big objects up the call stack is often not nearly as bad. Most of the time this happens, the object being spilled is constructed during the function, so the copy on return is actually elided.
- bugbuddy 3y agoThat’s only true if the function takes no argument. Otherwise the copy on return is unavoidable.
- pclmulqdq 3y agoThat's not actually true: https://en.cppreference.com/w/cpp/language/copy_elision https://en.cppreference.com/w/cpp/language/copy_elision
- gpderetta 3y agoI think parent is confused with NRVO typically not being triggered when returning a function argument.
- kukkamario 3y agoIn AMD64 ABI, anything larger (that doesn't fit in register) will be returned by basically output pointer argument. Caller reserves space for the return value and gives pointer to the function which then fills it with the return value. Both sides are easy to optimize and no unnecessary copies are made. Function can directly construct return value to the given address and caller can directly give a pointer to a variable if function return value is used to initialise variable.