Pl/Perl function: Speed of the First time executing pl/perl function in connection;

From: "Oleg Serov" <serovov(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Pl/Perl function: Speed of the First time executing pl/perl function in connection;
Date: 2008-11-15 22:36:12
Message-ID: cec7c6df0811151436s5b4aaf6br163c7975a575bbb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

When perl function executes first time, it is too slowly, but if
execute perl function(not function which executed first time) again it
runs in 1000 times faster. Why ? how can i optimize it ?
Configure shared_preload_libraries = '$libdir/plperl' or
local_preload_libraries = '$libdir/plugins/plperl' does not help;
Reproduce code:
-- First of all, creating functions
CREATE OR REPLACE FUNCTION "perl_test_speed" () RETURNS
"pg_catalog"."void" AS $body$;$body$ LANGUAGE 'plperl' VOLATILE CALLED
ON NULL INPUT SECURITY INVOKER;
CREATE OR REPLACE FUNCTION "perl_test_speed_two" () RETURNS
"pg_catalog"."void" AS $body$;$body$ LANGUAGE 'plperl' VOLATILE CALLED
ON NULL INPUT SECURITY INVOKER;

-- Reopen connection(THIS IS IMPORTANT STEP!)

-- Execute:
EXPLAIN ANALYZE SELECT perl_test_speed();
-- Result:
Result (cost=0.00..0.26 rows=1 width=0) (actual
time=149.994..149.999 rows=1 loops=1)
Total runtime: 150.363 ms -- WTF?
-- Other calls in this connection:
EXPLAIN ANALYZE SELECT perl_test_speed();
-- Result:
Result (cost=0.00..0.26 rows=1 width=0) (actual time=0.121..0.122
rows=1 loops=1)
Total runtime: 0.176 ms

-- Reopen connection(THIS IS IMPORTANT STEP!)

EXPLAIN ANALYZE SELECT perl_test_speed_two();
----------------------------------------------------------------------------------------
Result (cost=0.00..0.26 rows=1 width=0) (actual
time=173.713..173.716 rows=1 loops=1)
Total runtime: 174.073 ms -- WTF ?

EXPLAIN ANALYZE SELECT perl_test_speed();
------------------------------------------------------------------------------------
Result (cost=0.00..0.26 rows=1 width=0) (actual time=0.973..0.975
rows=1 loops=1)
Total runtime: 1.035 ms

EXPLAIN ANALYZE SELECT perl_test_speed();
------------------------------------------------------------------------------------
Result (cost=0.00..0.26 rows=1 width=0) (actual time=0.122..0.123
rows=1 loops=1)
Total runtime: 0.171 ms
-- END;

How can i make it run faster, after every reconnect ?
Thanks!
PS. Sorry for my English.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-11-15 22:39:49 Re: pgsql: Enable script to generate preproc.y in build process.
Previous Message Alex Hunsaker 2008-11-15 22:30:07 Re: patch: Client certificate requirements