public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/104719] New: Use of `std::move` in libstdc++ leads to worsened debug performance
@ 2022-02-28 16:20 vittorio.romeo at outlook dot com
  2022-02-28 16:46 ` [Bug libstdc++/104719] " redi at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: vittorio.romeo at outlook dot com @ 2022-02-28 16:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104719

            Bug ID: 104719
           Summary: Use of `std::move` in libstdc++ leads to worsened
                    debug performance
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vittorio.romeo at outlook dot com
  Target Milestone: ---

`std::accumulate` is defined as follows in `libstdc++`:

```
  template<typename _InputIterator, typename _Tp>
    _GLIBCXX20_CONSTEXPR
    inline _Tp
    accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
    {
      // concept requirements
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
      __glibcxx_requires_valid_range(__first, __last);

      for (; __first != __last; ++__first)
        __init = _GLIBCXX_MOVE_IF_20(__init) + *__first;
      return __init;
    }
```

Where `_GLIBCXX_MOVE_IF_20` is:

```
#if __cplusplus > 201703L
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 2055. std::move in std::accumulate and other algorithms
# define _GLIBCXX_MOVE_IF_20(_E) std::move(_E)
#else
# define _GLIBCXX_MOVE_IF_20(_E) _E
#endif
```

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`.
- With `std::move`: https://quick-bench.com/q/h_M_AUs3pgBE3bYr82rsA1_VtjU
- Without `std::move`: https://quick-bench.com/q/ysis2b1CgIZkRsO2cqfjZm9Jkio

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 `libstdc++` with
a cast, or some sort of compiler intrinsic? Or maybe mark `std::move` as
"always inline" even without optimizations enabled? 

Related issue for libc++:
https://github.com/llvm/llvm-project/issues/53689

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-05-04 15:55 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 16:20 [Bug libstdc++/104719] New: Use of `std::move` in libstdc++ leads to worsened debug performance vittorio.romeo at outlook dot com
2022-02-28 16:46 ` [Bug libstdc++/104719] " redi at gcc dot gnu.org
2022-02-28 16:50 ` redi at gcc dot gnu.org
2022-02-28 16:56 ` egallager at gcc dot gnu.org
2022-02-28 17:00 ` vittorio.romeo at outlook dot com
2022-02-28 17:16 ` redi at gcc dot gnu.org
2022-02-28 17:20 ` vittorio.romeo at outlook dot com
2022-02-28 17:24 ` redi at gcc dot gnu.org
2022-02-28 17:37 ` redi at gcc dot gnu.org
2022-03-01  2:23 ` vittorio.romeo at outlook dot com
2022-03-01 20:12 ` redi at gcc dot gnu.org
2022-03-01 20:14 ` redi at gcc dot gnu.org
2022-03-10 23:04 ` jason at gcc dot gnu.org
2022-03-26 23:37 ` jason at gcc dot gnu.org
2022-03-27  7:35 ` redi at gcc dot gnu.org
2022-05-04 15:34 ` cvs-commit at gcc dot gnu.org
2022-05-04 15:34 ` cvs-commit at gcc dot gnu.org
2022-05-04 15:49 ` unlvsur at live dot com
2022-05-04 15:55 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).