Обсуждение: Use bsearch() instead of a manual binary search in syscache.c

Поиск
Список
Период
Сортировка

Use bsearch() instead of a manual binary search in syscache.c

От
"cca5507"
Дата:
Hi, hackers!

I make a patch for the $subject, which make the code simpler, thoughts?

--
Regards,
ChangAo Chen

Вложения

Re: Use bsearch() instead of a manual binary search in syscache.c

От
Antonin Houska
Дата:
cca5507 <cca5507@qq.com> wrote:

> I make a patch for the $subject, which make the code simpler, thoughts?

I proposed something like that earlier [1] but did not get too far. The short
discussion might be useful for you though.

[1] https://www.postgresql.org/message-id/36977.1720623613@antos

-- 
Antonin Houska
Web: https://www.cybertec-postgresql.com



Re: Use bsearch() instead of a manual binary search in syscache.c

От
Thomas Munro
Дата:
On Sun, Nov 9, 2025 at 1:12 AM Antonin Houska <ah@cybertec.at> wrote:
> cca5507 <cca5507@qq.com> wrote:
> > I make a patch for the $subject, which make the code simpler, thoughts?
>
> I proposed something like that earlier [1] but did not get too far. The short
> discussion might be useful for you though.

One factor is that libc bsearch() implementations might not all be
header-only and inlineable.  I vaguely recall that being discussed in
some round of hacking on qsort() and qunique().



Re: Use bsearch() instead of a manual binary search in syscache.c

От
Tom Lane
Дата:
Thomas Munro <thomas.munro@gmail.com> writes:
> One factor is that libc bsearch() implementations might not all be
> header-only and inlineable.  I vaguely recall that being discussed in
> some round of hacking on qsort() and qunique().

I'm quite certain that years ago we determined that bsearch()
was slower than a manually written-out loop, probably because of
exactly the point that the comparisons would be inline.  Don't
know whether modern compilers have changed that conclusion.

There are places where we wouldn't care about such microscopic
performance details, but I think syscache.c is not one of them.

            regards, tom lane