Re: SQLFunctionCache and generic plans - Mailing list pgsql-hackers

From Alexander Pyhalov
Subject Re: SQLFunctionCache and generic plans
Date
Msg-id e5724d1ba8398c7ff20ead1de73b4db4@postgrespro.ru
Whole thread Raw
In response to Re: SQLFunctionCache and generic plans  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: SQLFunctionCache and generic plans
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Sadeq Dousti
Date:
Subject: Re: psql \dh: List High-Level (Root) Tables and Indexes
Next
From: Andrew Dunstan
Date:
Subject: Re: new commitfest transition guidance