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
Reini Urban
July 30, 2010 09:04
Re: Patch to make string-append on win32 100 times faster
Message ID:
Marvin Humphrey schrieb:
>> * 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.

I would rather align it to the pointer size, and keep an eye on the

I did similar tricks in Tie::CArray to get decent realloc
(array grow) performance.

#define PAGEBITS  11  /* we can also use 10 or 12, most system malloc to 
12 ie 4096 */
#define MY_PAGESIZE  (1 << PAGEBITS)    /* 2048 byte is the size of a 
fresh carray */
/* This is the to-tune part:
  * The overall size should fit into a page or other malloc chunks.
  * Leave room for "some" more items, but align it to the page size.
  * Should small arrays (<100) be aligned at 2048 or smaller bounds?
  * 10 => 2048-10, 2000 => 2048-2000, 200.000 => 2048
  * len is the actual length of the array, size the itemsize in bytes.
int freesize (int len, int size)
     len *= size;
     return max(MY_PAGESIZE-len, len - ((len >> PAGEBITS) << PAGEBITS)) 
/ size;
freesize is the slackspace to allocate additionally, and can be inlined.
grow by n:
ptr = saferealloc (ptr, len + freesize(len+n, itemsize));
Reini Urban

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