public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: "Александр Шитов" <alex.shitov1237@gmail.com>
Cc: libstdc++@gcc.gnu.org
Subject: Re: __lower_bound improvement for arithmetical types
Date: Fri, 10 Mar 2023 10:26:50 +0000	[thread overview]
Message-ID: <CAH6eHdRF1HDW_42yXDSEPYRscMcgGRogVgHqtxK8rPZ_BbG=jw@mail.gmail.com> (raw)
In-Reply-To: <CAP=JgFqDzDTkuBD7qOaL95Fum+vP=EP6mt5PZN98u10D5yX8rg@mail.gmail.com>

On Thu, 9 Mar 2023 at 19:58, Александр Шитов via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> I want to propose an improvement to std::__lower_bound for arithmetic types
> with the standard comparators.
>
>
> The main idea is to use linear search on a small number of elements to aid
> the branch predictor and CPU caches, but only when it is not observable by
> the user. In other words, if a standard comparator (std::less,
> std::greater) is used for arithmetic types.
>
>
> In benchmarks I achieved twice the increase in speed for small vectors(16
> elements) and increase for 10-20% in large vectors(1'000, 100'000 elements).
>
>
> Code: https://gist.github.com/ATGsan/8a1fdec92371d5778a65b01321c43604
>
> PR: https://github.com/ATGsan/gcc/pull/1

This is an interesting idea, thanks.

You limit the linear search to a single cacheline, but you don't
ensure that the range to search doesn't cross two cachelines, right?
Maybe it doesn't matter in practice, but I wonder if limiting the
linear search to a single cacheline would be even better.

  reply	other threads:[~2023-03-10 10:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09 19:57 Александр Шитов
2023-03-10 10:26 ` Jonathan Wakely [this message]
     [not found]   ` <CAP=JgFpBesxfVvcnWqE2ZmGt0s-H+4L6F1bBP2NbJiAnziCE7g@mail.gmail.com>
2023-03-29  6:26     ` Александр Шитов
2023-03-29  8:00       ` Jonathan Wakely
2023-05-13 12:02         ` Александр Шитов

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='CAH6eHdRF1HDW_42yXDSEPYRscMcgGRogVgHqtxK8rPZ_BbG=jw@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=alex.shitov1237@gmail.com \
    --cc=libstdc++@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).