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 = 10004Thread Previous | Thread Next