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
From:
Jim Cromie
Date:
July 30, 2010 21:37
Subject:
Re: Patch to make string-append on win32 100 times faster
Message ID:
AANLkTikSV1uk-4x4NgSzf62E-E-ZdWZtfFhJA7rqMs=d@mail.gmail.com
On Fri, Jul 30, 2010 at 3:26 PM,  <w.c.humann@arcor.de> wrote:
> From: Marvin Humphrey <marvin@rectangular.com>
> Date: 30.07.2010 17:34
>>>
>>> * 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
>>> anyway.
>>>
>>
>> That's similar to my analysis.  I think it's more useful to round up to a
>> multiple of the pointer size for small values.
>>
>
> If I understand correctly (which I'm not certain about), this is done anyway
> right afterwards in
> newlen = PERL_STRLEN_ROUNDUP(newlen);
>
> Wolfram
>
>

what happens if you presize the variable 1st ?
then assign an empty string,
then start appending the additions.

this will avoid all the sv_grow calls,
all the reallocs, and just use the one-time preallocated memory.

this avoids all the mods to the heuristics youre proposing
(modest tho they might be), and has no unintended effects
on other benchmarkable use cases.

Theres some perl way to do this without explicitly assigning a large string
(as I did below), but I cannot recall it, and cant think of a suitably narrow
search term/strategy for it (hints welcome)

length($s) = 1000000;  # isnt correct

[jimc@harpo perl]$ perl -MDevel::Peek -de1

main::(-e:1):	1
  DB<1> $s='a'x10000;

  DB<2> Dump $s
SV = PV(0x8c03df0) at 0x8c8c578
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x8ce9f48
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\0
  CUR = 10000
  LEN = 10004

  DB<3> $s='a'

  DB<4> Dump $s
SV = PV(0x8c03df0) at 0x8c8c578
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x8ce9f48 "a"\0
  CUR = 1
  LEN = 10004

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About