An other reason why subroutine should always end with an explicit
return.
XML::Twig has this XML::Parser handler for characters that ends
(or rather used to end!) with $elt->{pcdata} .= $string;.
This is the common case, but it's hidden in the middle of a few if/else's,
and it's actually an inlined method call. So it's not obvious what's
going on there. But this was what happened when the XML to be parsed
included a 4Mb, 60K line, base-64 encoded element: the handler was called
120K times (once for each line, once for each line return). For each of those
calls the current content of the element was returned by the handler, and
promptly discarded in the bowels of XML::Parser. Except that if you
count 120 000 * 4MB/2, that makes nearly 500 GB of memory that needed to
be allocated, copied and discarded, for absolutley no good reason at all.
In the end, adding a return at the end of the handler
took processing time from 581s to... 2s. It probably improves speed in
less specific cases.
And yes, it is one of Perl Best Practices recommendations (although not for
performance reasons). So were was the PBP in 1997 when I wrote the first version of XML::Twig?
A failure of the Perl core (Score:2)
Re:A failure of the Perl core, probably not (Score:2)
mirod
Re: (Score:1)
Re: (Score:2)
mirod