develooper Front page | perl.perl5.porters | Postings from July 2010

Re: Patch to make string-append on win32 100 times faster

Thread Previous | Thread Next
David Golden
July 30, 2010 07:30
Re: Patch to make string-append on win32 100 times faster
Message ID:
On Fri, Jul 30, 2010 at 9:37 AM, Wolfram Humann <> wrote:
> I would like to propose that perl requests an additional amount of memory
> from realloc when strings grow by a small amount.

+1 -- though I'm not clear whether this win32 specific or whether all
operating systems should work this way.

>    if (newlen > SvLEN(sv)) {        /* need more room? */
>        size_t minlen  = SvCUR(sv);
>        minlen += (minlen >> PERL_STRLEN_EXPAND_SHIFT) + 10;
>        if (newlen < minlen) newlen = minlen;

I have a few questions about the specific implementation.  Please
don't take them as suggestions that your approach is necessarily wrong
-- but I'd like to understand the logic behind certain choices.

* Why are you suggesting making the extra allocation proportional to
the length of the string?  Why not a multiple of the length of the
increment?  Why not a fixed amount?

* Why the "+10"?  Why have a extra minimum at all?  Why "10" instead
of another number?  Given your examples, for a large string the 10 is
a trivial fraction of the total and for a small string, the efficiency
either doesn't matter or the string quickly grows into a large string

* Why do you think PERL_STRLEN_EXPAND_SHIFT should be 2?  That's a 25%
increase in the length of the string.  (In many programs, I suspect
many strings are appended to only a few times and that seems like
large memory price to pay.)

> On current Strawberry Perl (5.10 or 5.12):
> a) 2.6 seconds
> b) 18 seconds
> Perl 5.12 compiled on win32 with modifications as above:
> a) 0.014 seconds
> b) 0.2 seconds

Awesome!  What does it look like with a shift of 3 or 4?

-- David

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About