From: Nicholas Clark Date: Sat, 7 Oct 2006 23:42:56 +0000 (+0000) Subject: Yves said that the XS version of Data::Dumper was inefficient because X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9fa5cce2ac5fe91228c7c54739f581c98f0738ef;p=p5sagit%2Fp5-mst-13.2.git Yves said that the XS version of Data::Dumper was inefficient because it keeps triggering realloc() due to sv_cat(). Here's a rather brute force approach to pre-stretching the buffer - if there are less than 40 bytes free, grow it by 50%. Surprisingly effective for my test program ./perl -Ilib -MData::Dumper -MStorable=retrieve -we \ 'print Dumper(retrieve(shift))' ~/.cpan/Metadata >/dev/null Before real 2m42.921s user 1m43.321s sys 0m55.611s After real 0m5.205s user 0m4.885s sys 0m0.255s Same 25M of output, byte for byte. :-) p4raw-id: //depot/perl@28963 --- diff --git a/ext/Data/Dumper/Dumper.xs b/ext/Data/Dumper/Dumper.xs index 36383dc..dbdc2d6 100644 --- a/ext/Data/Dumper/Dumper.xs +++ b/ext/Data/Dumper/Dumper.xs @@ -274,6 +274,9 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, if (!val) return 0; + if (SvTYPE(retval) >= SVt_PV && (SvLEN(retval) - SvCUR(retval)) < 40) { + sv_grow(retval, SvCUR(retval) * 1.5); + } realtype = SvTYPE(val); if (SvGMAGICAL(val))