Re: Invocation overhead for procedural languages

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Giorgio Valoti" <giorgio_v(at)mac(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Invocation overhead for procedural languages
Date: 2008-08-06 14:04:56
Message-ID: 162867790808060704m643ed8c2i7dcb1e0bcd114128@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2008/8/6 Giorgio Valoti <giorgio_v(at)mac(dot)com>:
> Hi all, I think I've read somewhere in the documentation that the invocation
> of functions written in procedural languages (with the exception of plpgsql)
> incur in performance hit due to the call the language interpreter. Is that
> correct or am I completely off track?

it's depend. Start of interpret is only one overhead. Other is date
conversions to language compatible types (without C and plpgsql).
Only plpgsql share expression evaluation with database, so it's
specific overhead only for plpgsql.

postgres=# create function testpg(a integer) returns integer as
$$begin return 1; end; $$ language plpgsql immutable;
CREATE FUNCTION
postgres=# create function testperl(a integer) returns integer as
$$return 1;$$ language plperl;
CREATE FUNCTION

postgres=# select sum(testperl(i)) from generate_series(1,10000) g(i);
sum
-------
10000
(1 row)

Time: 588,649 ms
postgres=# select sum(testpg(i)) from generate_series(1,10000) g(i);
sum
-------
10000
(1 row)

Time: 51,214 ms

so in this trivial function is plpgql faster then perl, that is fata morgana :).

first start is diferent:
postgres=# select testpg(1);
testpg
--------
1
(1 row)

Time: 3,409 ms
postgres=# select testperl(1);
testperl
----------
1
(1 row)

Time: 86,199 ms
second is similar
postgres=# select testperl(1);
testperl
----------
1
(1 row)

Time: 1,059 ms
postgres=# select testpg(1);
testpg
--------
1
(1 row)

Time: 0,955 ms

but you can load perl after server start - look on preload_libraries
section in postgresql.conf

regards
Pavel Stehule

>
> Thank you in advance
> --
> Giorgio Valoti
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-08-06 14:10:39 Re: bytea encode performance issues
Previous Message Martin Gainty 2008-08-06 13:58:08 Re: Invocation overhead for procedural languages