public inbox for [email protected]  
help / color / mirror / Atom feed
From: Alexander Pyhalov <[email protected]>
To: Pavel Stehule <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: Alexander Korotkov <[email protected]>
Cc: [email protected]
Cc: Ronan Dunklau <[email protected]>
Subject: Re: SQLFunctionCache and generic plans
Date: Thu, 27 Feb 2025 15:25:03 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAFj8pRD-JcaGCktoWqGTt7TEb1zgENajVQwuhbHFfSMRH7+XPw@mail.gmail.com>
References: <8216639.NyiUUSuA9g@aivenlaptop>
	<[email protected]>
	<[email protected]>
	<CAPpHfdue9RVJKo33jKwrCeEXec0BTTH7CTxVcyXGMbfMExaGLA@mail.gmail.com>
	<[email protected]>
	<CAFj8pRCoR9B+Ap70TQqWUa0PeeEk94D6VW20YbWN2Pm4b6-JMQ@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAFj8pRD2Fa84HoH_R_S5aKngyA6a+Au7U6NyidfBMrwEjFAc9g@mail.gmail.com>
	<[email protected]>
	<CAFj8pRC_4gEfmDoB5KbacNDdt3e6Tnf1z1BFK=MVp3+2kcDVqw@mail.gmail.com>
	<CAFj8pRA7MFTfUPwDDWtghaUvAjbrMHFUPbHyLSX3h8+FDw4WFg@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAFj8pRD-JcaGCktoWqGTt7TEb1zgENajVQwuhbHFfSMRH7+XPw@mail.gmail.com>

Pavel Stehule писал(а) 2025-02-26 22:34:
> hI
> 
> I can confirm 60% speedup for execution of function fx and fx3 - both
> functions are very primitive, so for real code the benefit can be
> higher
> 
> Unfortunately, there is about 5% slowdown for inlined code, and for
> just plpgsql code too.
> 
> I tested fx4
> 
> create or replace function fx4(int) returns int immutable as $$ begin
> return $1 + $1; end $$ language plpgsql;
> 
> and fx2
> 
> create or replace function fx2(int) returns int as $$ select 2 * $1;
> $$
> language sql immutable;
> 
> and execution of patched code is about 5% slower. It is strange so
> this patch has a negative impact on plpgsql execution.
> 
> Regards
> 
> Pavel

Hi. I've tried to reproduce slowdown and couldn't.

create or replace function fx4(int) returns int immutable as $$ begin 
return $1 + $1; end $$ language plpgsql;

do $$
begin
   for i in 1..5000000 loop
     perform fx4((random()*100)::int); -- or fx2
   end loop;
end;
$$;

OLD results:
Time: 8268.614 ms (00:08.269)
Time: 8178.836 ms (00:08.179)
Time: 8306.694 ms (00:08.307)

New (patched) results:
Time: 7743.945 ms (00:07.744)
Time: 7803.109 ms (00:07.803)
Time: 7736.735 ms (00:07.737)

Not sure why new is faster (perhaps, some noise?) - looking at perf 
flamegraphs I don't see something evident.

create or replace function fx2(int) returns int as $$ select 2 * $1; $$ 
language sql immutable;
do $$
begin
   for i in 1..5000000 loop
     perform fx2((random()*100)::int); -- or fx2
   end loop;
end;
$$;

OLD results:
Time: 5346.471 ms (00:05.346)
Time: 5359.222 ms (00:05.359)
Time: 5316.747 ms (00:05.317)

New (patched) results:
Time: 5188.363 ms (00:05.188)
Time: 5225.322 ms (00:05.225)
Time: 5203.667 ms (00:05.204)

-- 
Best regards,
Alexander Pyhalov,
Postgres Professional






view thread (35+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: SQLFunctionCache and generic plans
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox