std::accumulate is defined as follows in libc++:
template <class _InputIterator, class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{
for (; __first != __last; ++__first)
#if _LIBCPP_STD_VER > 17
__init = _VSTD::move(__init) + *__first;
#else
__init = __init + *__first;
#endif
return __init;
}
When compiling a program using std::accumulate in debug mode, under -Og, there is a noticeable performance impact due to the presence of std::move.
This performance degradation is one example of why many people (especially in the gamedev community) are not adopting standard library algorithms and modern C++ more widely.
Would it be possible to replace std::move calls internal to libc++ with a cast, or some sort of compiler intrinsic? Or maybe mark std::move as "always inline" even without optimizations enabled?
std::accumulateis defined as follows inlibc++:When compiling a program using
std::accumulatein debug mode, under-Og, there is a noticeable performance impact due to the presence ofstd::move.std::move: https://quick-bench.com/q/h_M_AUs3pgBE3bYr82rsA1_VtjUstd::move: https://quick-bench.com/q/ysis2b1CgIZkRsO2cqfjZm9JkioThis performance degradation is one example of why many people (especially in the gamedev community) are not adopting standard library algorithms and modern C++ more widely.
Would it be possible to replace
std::movecalls internal tolibc++with a cast, or some sort of compiler intrinsic? Or maybe markstd::moveas "always inline" even without optimizations enabled?