Re: Use bsearch() instead of a manual binary search in syscache.c - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: Use bsearch() instead of a manual binary search in syscache.c
Date
Msg-id CA+hUKG+6c2Yqp6OgVjGWzKn9EbaeWs-p9jaEeTBXJ62O0CougA@mail.gmail.com
Whole thread Raw
In response to Re: Use bsearch() instead of a manual binary search in syscache.c  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Use bsearch() instead of a manual binary search in syscache.c
List pgsql-hackers
On Sun, Nov 9, 2025 at 6:01 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 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.

It looks like glibc's version is inlined, but others I checked aren't.

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

So we'd probably need our own inline function to keep the playing
field level.  Some tweaked algorithms[1] are also said to speed up
small integer tables, Unicode tables etc.

[1] https://github.com/scandum/binary_search



pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: MSVC: Improve warning options set
Next
From: Xuneng Zhou
Date:
Subject: Re: Add tab completion support for WAIT FOR command