Bug 90409 - std::move[_backward] could be more optimized for deque iterators
Summary: std::move[_backward] could be more optimized for deque iterators
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 9.1.0
: P3 enhancement
Target Milestone: 11.0
Assignee: François Dumont
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2019-05-09 12:07 UTC by Morwenn
Modified: 2020-06-30 20:00 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-05-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Morwenn 2019-05-09 12:07:41 UTC
The standard library currently contains optimized versions of std::move and std::move_backward for std::deque iterators, which move everything block per block. However those overloads only work when both the input and output iterators are std::deque iterators, and not when the types of iterators differ.

I noticed that lately when checking the performance of merge algorithms on std::deque algorithms: I expected memmove to be called when calling std::move to move the contents of a std::deque to a temporary buffer (represented by a simple pointer) and when moving the elements back from the buffer to the std::deque, but while memmove was called as expected when using libc++, it wasn't when using libstdc++. I looked at the standard library code and that's when I realized that the libstdc++ overloads for deque iterators didn't accept mixed iterators.

Would it be possible to add std::[_backward] overloads to take this case into account? If I'm not mistaken it should improve std::inplace_merge and std::stable_sort out of the box for std::deque<T> iterators when T is trivially copyable.
Comment 1 François Dumont 2019-07-03 20:26:18 UTC
Patch awaiting on mailing list:

https://gcc.gnu.org/ml/libstdc++/2019-06/msg00097.html
Comment 2 François Dumont 2020-06-30 20:00:00 UTC
The different patches have been applied.