Re: Linux likely() unlikely() for PostgreSQL

2024-08-12 Thread David Rowley
On Mon, 12 Aug 2024 at 20:34, John Naylor wrote: > I just remembered an article I read a while back by a compiler > engineer who said that compilers have heuristics that treat NULL > pointers as "unlikely" since the most common reason to test that is so > we can actually dereference it and do some

Re: Linux likely() unlikely() for PostgreSQL

2024-08-12 Thread John Naylor
On Sun, Jun 30, 2024 at 10:24 PM Tom Lane wrote: > In general, we have a policy of using likely/unlikely very sparingly, > and only in demonstrably hot code paths. This hook call certainly > doesn't qualify as hot. I just remembered an article I read a while back by a compiler engineer who said

Re: Linux likely() unlikely() for PostgreSQL

2024-07-04 Thread Andres Freund
Hi, On 2024-06-30 16:47:02 +0200, Matthias van de Meent wrote: > While hooks are generally not installed by default, I would advise > against marking the hooks as unlikely, as that would unfairly penalize > the performance of extensions that do utilise this hook (or hooks in > general when applied

Re: Linux likely() unlikely() for PostgreSQL

2024-06-30 Thread David Rowley
On Mon, 1 Jul 2024 at 14:08, Peter Geoghegan wrote: > > On Sun, Jun 30, 2024 at 11:23 AM Tom Lane wrote: > > if (trouble) > > ereport(ERROR, ...); > > > > could be interpreted as > > > > if (unlikely(trouble)) > > ereport(ERROR, ...); > > > > But I

Re: Linux likely() unlikely() for PostgreSQL

2024-06-30 Thread Peter Geoghegan
On Sun, Jun 30, 2024 at 11:23 AM Tom Lane wrote: > The real win would be if constructs like > > if (trouble) > ereport(ERROR, ...); > > could be interpreted as > > if (unlikely(trouble)) > ereport(ERROR, ...); > > But I surely don't want to make thou

Re: Linux likely() unlikely() for PostgreSQL

2024-06-30 Thread wenhui qiu
Hi Tom ,Matthias Thank you for your explanation.Maybe future compilers will be able to do intelligent prediction? Thanks Tom Lane 于2024年6月30日周日 23:23写道: > Matthias van de Meent writes: > > On Sun, 30 Jun 2024, 15:56 wenhui qiu, wrote: > >> if (unlikely(ExecutorRun_hook)), > > > While ho

Re: Linux likely() unlikely() for PostgreSQL

2024-06-30 Thread Tom Lane
Matthias van de Meent writes: > On Sun, 30 Jun 2024, 15:56 wenhui qiu, wrote: >> if (unlikely(ExecutorRun_hook)), > While hooks are generally not installed by default, I would advise > against marking the hooks as unlikely, as that would unfairly penalize > the performance of extensions that do

Re: Linux likely() unlikely() for PostgreSQL

2024-06-30 Thread Matthias van de Meent
On Sun, 30 Jun 2024, 15:56 wenhui qiu, wrote: > > Hi Hackers >When I saw this document:https://en.wikipedia.org/wiki/Branch_predictor, I > thought of Linux likely() vs unlikely() and thus thought that there are some > code segments in src/backend/executor/execMain.c that can be optimized. >

Linux likely() unlikely() for PostgreSQL

2024-06-30 Thread wenhui qiu
Hi Hackers When I saw this document:https://en.wikipedia.org/wiki/Branch_predictor, I thought of Linux likely() vs unlikely() and thus thought that there are some code segments in src/backend/executor/execMain.c that can be optimized. For example : if (ExecutorStart_hook) (*ExecutorStart_hook) (