public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Mark_B53 at yahoo dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/108487] [10/11/12/13 Regression] ~20-30x slowdown in populating std::vector from std::ranges::iota_view
Date: Sun, 22 Jan 2023 10:33:50 +0000	[thread overview]
Message-ID: <bug-108487-4-LvhtsKYr0q@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108487-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from Mark Bourgeault <Mark_B53 at yahoo dot com> ---
What about something like this?

#if __cplusplus >= 201709L
      template<typename _InputIterator,
               typename = std::_RequireInputIter<_InputIterator>>
        vector(_InputIterator __first, _InputIterator __last,
               const allocator_type& __a = allocator_type())
        : _Base(__a)
        {
          struct PseudoRange { _InputIterator begin(); _InputIterator end(); };
          if constexpr (std::ranges::random_access_range<PseudoRange>) {
            _M_range_initialize(__first, __last,
                              std::random_access_iterator_tag());
          }
          else if constexpr (std::ranges::forward_range<PseudoRange>) {
            _M_range_initialize(__first, __last, std::forward_iterator_tag());
          }
          else {
            _M_range_initialize(__first, __last,
                              std::__iterator_category(__first));
        }
#else
  ...
#endif

-----

Here is a PoC:

#include <vector>
#include <ranges>
#include <iostream>

template<typename I>
void test(I first, I last) {
    struct PseudoRange { I begin(); I end(); };
    if constexpr (std::ranges::random_access_range<PseudoRange>) {
        std::cout << "RA\n"; 
    }
    else if constexpr (std::ranges::forward_range<PseudoRange>) {
        std::cout << "F\n"; 
    }
    else  {
        std::cout << "I\n"; 
    }
}

int main() {
    auto rng = std::ranges::iota_view{0, 10} | std::views::transform([](int i)
{ return i*i; });
    test(rng.begin(), rng.end());
    auto rng2 = std::ranges::iota_view{0, 10} | std::views::filter([](int i) {
return i%2; });
    test(rng2.begin(), rng2.end());
    return 0;
}

  parent reply	other threads:[~2023-01-22 10:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 22:20 [Bug rtl-optimization/108487] New: " Mark_B53 at yahoo dot com
2023-01-21 11:48 ` [Bug tree-optimization/108487] [10/11/12/13 Regression] " amonakov at gcc dot gnu.org
2023-01-21 13:32 ` Mark_B53 at yahoo dot com
2023-01-21 15:38 ` [Bug libstdc++/108487] " amonakov at gcc dot gnu.org
2023-01-21 23:45 ` redi at gcc dot gnu.org
2023-01-21 23:50 ` redi at gcc dot gnu.org
2023-01-21 23:50 ` redi at gcc dot gnu.org
2023-01-22  3:07 ` Mark_B53 at yahoo dot com
2023-01-22 10:33 ` Mark_B53 at yahoo dot com [this message]
2023-01-22 17:14 ` redi at gcc dot gnu.org
2023-01-23  7:45 ` rguenth at gcc dot gnu.org
2023-03-27 11:03 ` rguenth at gcc dot gnu.org
2023-07-07 10:44 ` [Bug libstdc++/108487] [11/12/13/14 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108487-4-LvhtsKYr0q@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).