On Tue, Dec 7, 2010 at 07:24, Tim Bunce <tim.bu...@pobox.com> wrote: > Changes: > > Sets the local $_TD via C instead of passing an extra argument. > So functions no longer start with "our $_TD; local $_TD = shift;" > > Pre-extend stack for trigger arguments for slight performance gain. > > Passes installcheck.
Cool, surprisingly in the non trigger case I saw up to an 18% speedup. The trigger case remained about the same, I suppose im I/O bound. Find attached a v2 with some minor fixes, If it looks good to you Ill mark this as "Ready for Commit". Changes: - move up a declaration to make it c90 safe - avoid using tg_trigger before it was initialized - only extend the stack to the size we need (there was + 1 which unless I am missing something was needed because we used to push $_TD on the stack, but we dont any more) Benchmarks: --- create table t (a int); create or replace function func(int) returns int as $$ return $_[0]; $$ language plperl; create or replace function trig() returns trigger as $$ $_TD->{'new'}{'a'}++; return 'MODIFY'; $$ language plperl; -- pre patch, simple function call, 3 runs SELECT sum(func(1)) from generate_series(1, 10000000); Time: 30908.675 ms Time: 30916.995 ms Time: 31173.122 ms -- post patch SELECT sum(func(1)) from generate_series(1, 10000000); Time: 26460.987 ms Time: 26465.480 ms Time: 25958.016 ms -- pre patch, trigger insert into t (a) select generate_series(1, 1000000); Time: 18186.390 ms Time: 21291.721 ms Time: 20782.238 ms -- post insert into t (a) select generate_series(1, 1000000); Time: 19136.633 ms Time: 21140.095 ms Time: 22062.578 ms
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 5595baa..7fb69df 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1421,7 +1421,7 @@ plperl_create_sub(plperl_proc_desc *prodesc, char *s, Oid fn_oid) EXTEND(SP, 4); PUSHs(sv_2mortal(newSVstring(subname))); PUSHs(sv_2mortal(newRV_noinc((SV *) pragma_hv))); - PUSHs(sv_2mortal(newSVstring("our $_TD; local $_TD=shift;"))); + PUSHs(&PL_sv_no); /* unused */ PUSHs(sv_2mortal(newSVstring(s))); PUTBACK; @@ -1493,9 +1493,7 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo) SAVETMPS; PUSHMARK(SP); - EXTEND(sp, 1 + desc->nargs); - - PUSHs(&PL_sv_undef); /* no trigger data */ + EXTEND(sp, desc->nargs); for (i = 0; i < desc->nargs; i++) { @@ -1575,21 +1573,22 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, SV *td) { dSP; - SV *retval; - Trigger *tg_trigger; - int i; - int count; + SV *retval, *TDsv; + int i, count; + Trigger *tg_trigger = ((TriggerData *) fcinfo->context)->tg_trigger; ENTER; SAVETMPS; - PUSHMARK(sp); + TDsv = get_sv("_TD", GV_ADD); + SAVESPTR(TDsv); /* local $_TD */ + sv_setsv(TDsv, td); - XPUSHs(td); + PUSHMARK(sp); + EXTEND(sp, tg_trigger->tgnargs); - tg_trigger = ((TriggerData *) fcinfo->context)->tg_trigger; for (i = 0; i < tg_trigger->tgnargs; i++) - XPUSHs(sv_2mortal(newSVstring(tg_trigger->tgargs[i]))); + PUSHs(sv_2mortal(newSVstring(tg_trigger->tgargs[i]))); PUTBACK; /* Do NOT use G_KEEPERR here */
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers