Subject: | Expat.xs performance, callbacks need to be in void context |
Hi, the following perlmonks thread
XML::Parser ( or Perl internals ) speed mysticism
http://perlmonks.org/?node_id=539223
has hilighted that callbacks (and methods)
whose return values aren't used,
aren't being called in void context,
which can impact performance significantly.
Patch is attached (test suite passes, speeds things up).
Subject: | Expat.xs.patch |
--- Expat/Expat.xs 2006-03-26 08:27:27.281250000 -0800
+++ Expat/Expat.xs.new 2006-03-26 08:27:05.500000000 -0800
@@ -467,7 +467,7 @@
PUSHs(cbv->self_sv);
PUSHs(sv_2mortal(newUTF8SVpvn((char*)s,len)));
PUTBACK;
- perl_call_sv(cbv->char_sv, G_DISCARD);
+ perl_call_sv(cbv->char_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -536,7 +536,7 @@
PUSHs(sv_2mortal(newUTF8SVpv((char*)*atts++,0)));
}
PUTBACK;
- perl_call_sv(cbv->start_sv, G_DISCARD);
+ perl_call_sv(cbv->start_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -572,7 +572,7 @@
PUSHs(cbv->self_sv);
PUSHs(elname);
PUTBACK;
- perl_call_sv(cbv->end_sv, G_DISCARD);
+ perl_call_sv(cbv->end_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -598,7 +598,7 @@
PUSHs(sv_2mortal(newUTF8SVpv((char*)target,0)));
PUSHs(sv_2mortal(newUTF8SVpv((char*)data,0)));
PUTBACK;
- perl_call_sv(cbv->proc_sv, G_DISCARD);
+ perl_call_sv(cbv->proc_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -618,7 +618,7 @@
PUSHs(cbv->self_sv);
PUSHs(sv_2mortal(newUTF8SVpv((char*) string, 0)));
PUTBACK;
- perl_call_sv(cbv->cmnt_sv, G_DISCARD);
+ perl_call_sv(cbv->cmnt_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -637,7 +637,7 @@
PUSHMARK(sp);
XPUSHs(cbv->self_sv);
PUTBACK;
- perl_call_sv(cbv->startcd_sv, G_DISCARD);
+ perl_call_sv(cbv->startcd_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -657,7 +657,7 @@
PUSHMARK(sp);
XPUSHs(cbv->self_sv);
PUTBACK;
- perl_call_sv(cbv->endcd_sv, G_DISCARD);
+ perl_call_sv(cbv->endcd_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -678,7 +678,7 @@
PUSHs(prefix ? sv_2mortal(newUTF8SVpv((char *)prefix, 0)) : &PL_sv_undef);
PUSHs(uri ? sv_2mortal(newUTF8SVpv((char *)uri, 0)) : &PL_sv_undef);
PUTBACK;
- perl_call_method("NamespaceStart", G_DISCARD);
+ perl_call_method("NamespaceStart", G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -697,7 +697,7 @@
PUSHs(cbv->self_sv);
PUSHs(prefix ? sv_2mortal(newUTF8SVpv((char *)prefix, 0)) : &PL_sv_undef);
PUTBACK;
- perl_call_method("NamespaceEnd", G_DISCARD);
+ perl_call_method("NamespaceEnd", G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -717,7 +717,7 @@
PUSHs(cbv->self_sv);
PUSHs(sv_2mortal(newUTF8SVpvn((char*)string, len)));
PUTBACK;
- perl_call_sv(cbv->dflt_sv, G_DISCARD);
+ perl_call_sv(cbv->dflt_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -744,7 +744,7 @@
PUSHs(sv_2mortal(newUTF8SVpv((char *)name, 0)));
PUSHs(sv_2mortal(cmod));
PUTBACK;
- perl_call_sv(cbv->eledcl_sv, G_DISCARD);
+ perl_call_sv(cbv->eledcl_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -782,7 +782,7 @@
if (dflt && reqorfix)
XPUSHs(&PL_sv_yes);
PUTBACK;
- perl_call_sv(cbv->attdcl_sv, G_DISCARD);
+ perl_call_sv(cbv->attdcl_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -815,7 +815,7 @@
if (isparam)
XPUSHs(&PL_sv_yes);
PUTBACK;
- perl_call_sv(cbv->entdcl_sv, G_DISCARD);
+ perl_call_sv(cbv->entdcl_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -841,7 +841,7 @@
PUSHs(pubid ? sv_2mortal(newUTF8SVpv((char*)pubid, 0)) : &PL_sv_undef);
PUSHs(hasinternal ? &PL_sv_yes : &PL_sv_no);
PUTBACK;
- perl_call_sv(cbv->doctyp_sv, G_DISCARD);
+ perl_call_sv(cbv->doctyp_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
} /* End doctypeStart */
@@ -858,7 +858,7 @@
EXTEND(sp, 1);
PUSHs(cbv->self_sv);
PUTBACK;
- perl_call_sv(cbv->doctypfin_sv, G_DISCARD);
+ perl_call_sv(cbv->doctypfin_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
} /* End doctypeEnd */
@@ -884,7 +884,7 @@
PUSHs(standalone == -1 ? &PL_sv_undef
: (standalone ? &PL_sv_yes : &PL_sv_no));
PUTBACK;
- perl_call_sv(cbv->xmldec_sv, G_DISCARD);
+ perl_call_sv(cbv->xmldec_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
} /* End xmlDecl */
@@ -912,7 +912,7 @@
PUSHs(pubid ? sv_2mortal(newUTF8SVpv((char*) pubid, 0)) : &PL_sv_undef);
PUSHs(sv_2mortal(newUTF8SVpv((char*) notation, 0)));
PUTBACK;
- perl_call_sv(cbv->unprsd_sv, G_DISCARD);
+ perl_call_sv(cbv->unprsd_sv, G_DISCARD|G_VOID);
FREETMPS;
LEAVE;
@@ -953,7 +953,7 @@
XPUSHs(sv_2mortal(newUTF8SVpv((char *) pubid, 0)));
PUTBACK;
- perl_call_sv(cbv->notation_sv, G_DISCARD);
+ perl_call_sv(cbv->notation_sv, G_DISCARD|G_VOID);
} /* End notationDecl */
static int
@@ -1047,7 +1047,7 @@
PUSHMARK(sp);
PUSHs(cbv->self_sv);
PUTBACK;
- perl_call_sv(cbv->extfin_sv, G_DISCARD);
+ perl_call_sv(cbv->extfin_sv, G_DISCARD|G_VOID);
SPAGAIN;
}
@@ -1150,7 +1150,7 @@
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSVpvn(buff,namelen)));
PUTBACK;
- perl_call_pv("XML::Parser::Expat::load_encoding", G_DISCARD);
+ perl_call_pv("XML::Parser::Expat::load_encoding", G_DISCARD|G_VOID);
encinfptr = hv_fetch(EncodingTable, buff, namelen, 0);
FREETMPS;