Skip to content

Use of std::move in libc++ leads to worsened debug performance  #53689

Description

@vittorioromeo

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions