Re: Linux likely() unlikely() for PostgreSQL

Поиск
Список
Период
Сортировка
От Matthias van de Meent
Тема Re: Linux likely() unlikely() for PostgreSQL
Дата
Msg-id CAEze2Whn=6XVCqMNeka7C3VYXua0KH56h9S2=9Ps42hdyXwfmQ@mail.gmail.com
обсуждение исходный текст
Ответ на Linux likely() unlikely() for PostgreSQL  (wenhui qiu <qiuwenhuifx@gmail.com>)
Список pgsql-hackers
On Sun, 30 Jun 2024, 15:56 wenhui qiu, <qiuwenhuifx@gmail.com> wrote:
>
> Hi Hackers
>    When I saw this document:https://en.wikipedia.org/wiki/Branch_predictor, I thought of Linux likely() vs unlikely()
andthus thought that there are some code segments in src/backend/executor/execMain.c that can be optimized. 
> For example :
> if (ExecutorStart_hook)
> (*ExecutorStart_hook) (queryDesc, eflags);
> else
> standard_ExecutorStart(queryDesc, eflags);
> }
> void
> ExecutorRun(QueryDesc *queryDesc,
> ScanDirection direction, uint64 count,
> bool execute_once)
> {
> if (ExecutorRun_hook)
> (*ExecutorRun_hook) (queryDesc, direction, count, execute_once);
> else
> standard_ExecutorRun(queryDesc, direction, count, execute_once);
> }
> ###
> if (unlikely(ExecutorRun_hook)),
>
> I hope to get guidance from community experts,Many thanks

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 to all hooks).

If this code is hot enough, then CPU branch prediction will likely
correctly predict this branch correctly after a small amount of time
(as hook null-ness is generally approximately constant for the
duration of a backend lifetime); while if this code is cold, the
benefit is not worth the additional binary size overhead of the
out-of-lined code section.


Kind regards,

Matthias van de Meent
Neon (https://neon.tech/)



В списке pgsql-hackers по дате отправления:

Предыдущее
От: wenhui qiu
Дата:
Сообщение: Linux likely() unlikely() for PostgreSQL